import re
regex = re.compile(r"^([5-9]\d{1}\d*|\d{3}\d*)$", flags=re.MULTILINE)
test_str = ("1\n"
"12\n"
"33\n"
"49\n"
"50\n"
"51\n"
"60\n"
"77\n"
"99\n"
"100\n"
"101\n"
"102\n"
"999\n"
"444\n"
"333\n"
"9999\n"
"10001\n"
"10000\n"
"10930\n"
"10903\n"
"11022\n"
"11014\n"
"11099\n"
"11100\n"
"11111\n"
"11562\n"
"11234\n"
"12453\n"
"22222\n"
"232312\n"
"200000\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