import re
regex = re.compile(r"^(?:(?=(?:\s*\d\s*){10}$)(?:0\s*[2378]|1[38])|(?=(?:\s*\d\s*){6}$)1\s*3).*", flags=re.MULTILINE)
test_str = ("0299998888\n"
"02 99998888\n"
"02 9999 8888\n"
"02 99 998 888\n"
"0299 998 888\n"
"0299 998888\n"
"131999\n"
"131 999\n"
"13 19 99\n"
"1300123456\n"
"1300 123456\n"
"1300 123 456\n"
"1300 12 34 56\n"
"1300 12 34 56\n"
"13145\n"
"1300-123-456\n"
"9999 8888\n"
"(02) 9999 8888")
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