import re
regex = re.compile(r"(^[2-9][0-9]{2}$)|(^[1-2][0-9]{3}$)", flags=re.MULTILINE)
test_str = ("1\n"
"12\n"
"19\n"
"20\n"
"21\n"
"29\n"
"30\n"
"31\n"
"40\n"
"50\n"
"60\n"
"70\n"
"80\n"
"98\n"
"99\n"
"100\n"
"101\n"
"102\n"
"149\n"
"150\n"
"180\n"
"190\n"
"199\n"
"200\n"
"201\n"
"202\n"
"300\n"
"400\n"
"500\n"
"600\n"
"999\n"
"1000\n"
"1001\n"
"1002\n"
"2000\n"
"3000\n"
"9999\n"
"10000\n"
"10001\n"
"10002\n"
"10003\n"
"19999\n"
"20000\n"
"20001\n"
"20002\n"
"30000\n"
"50000\n"
"60000\n"
"99999\n"
"100000\n"
"100001\n"
"30000000\n")
matches = regex.finditer(test_str)
for match_num, match in enumerate(matches, start=1):
print(f"Match {match_num} was found at {match.start()}-{match.end()}: {match.group()}")
for group_num, group in enumerate(match.groups(), start=1):
print(f"Group {group_num} found at {match.start(group_num)}-{match.end(group_num)}: {group}")
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Python, please visit: https://docs.python.org/3/library/re.html