import re
regex = re.compile(r"^[-a-zA-Z0-9#$%'_]+(\.[-a-zA-Z0-9#$%'_]+)*@(([-a-zA-Z0-9]+)\.)+(?!\d+$)[a-zA-Z0-9]{2,}$", flags=re.MULTILINE)
test_str = ("Aba@example.com\n"
"test@test-test.com.com\n"
"test.abc-efg'@test-test.com.com.01111co\n"
"simple@example.com\n"
"very.common@example.com\n"
"other.email-with-hyphen@example.com\n"
"fully-qualified-domain@example.com\n"
"example-indeed@strange-example.com\n"
"example@s.example\n"
"Abc.example.com\n"
"A@b@c@example.com\n"
"just\"not\"right@example.com\n"
"this is\"not\\allowed@example.com\n"
"1234567890123456789012345678901234567890123456789012345678901234+x@example.com\n"
"john..doe@example.com\n"
"john.doe@example..com\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