import re text = '0412020982012'rg = r'20[1-2]\d+'years = re.compile("(%s)" % (rg)).findall(text) print(years)
Standard input is empty
['2020982012']
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!