import re
regex = re.compile(r"\d{8}[A-Z]\d{5}")
test_str = ("123456789\n"
"987654321\n"
"987654322\n"
"987654323\n"
"98765432A12312\n"
"987654325\n"
"987654326\n"
"987654327\n"
"987654328\n"
"987654329\n"
"666218502\n"
"773218502\n"
"772218502\n"
"443218502\n"
"641218502\n"
"525.52.6969B\n"
"515-54-6976-A\n"
"555516316S\n"
"123.45.6789\n"
"987.65.4321\n"
"987.65.4322\n"
"987.65.4323\n"
"987.65.4324\n"
"987.65.4325\n"
"987.65.4326\n"
"987.65.4327\n"
"987.65.4328\n"
"987.65.4329\n"
"666.21.8502\n"
"773.21.8502\n"
"772.21.8502\n"
"772-21-8502\n"
"772218502\n"
"443.21.8502\n"
"641.21.8502")
match = regex.search(test_str)
if match:
print(f"Match 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