import re
regex = re.compile(r"\d{1,2}.\d{1,2}.20\d{2}", flags=re.MULTILINE)
test_str = ("Example 1 (Colon)\n"
"Payee: John Smith\n"
"Account No: 145-567-981\n"
"Date: 19.01.2020\n"
"Time: 08:01\n"
"Email: JohnSmith@gmail.com\n\n"
"Example 2 (the dash)\n"
"John Smith - Payee\n"
"145 567 981 - Account No\n"
"19-01-2020 - Date\n"
"08:01 - Time\n"
"John.Smith@hotmail.com - Email\n\n"
"Example 3 (the dashes AND all one line of text)\n"
"Payee - John Smith - Account No - 145.567.9815 - Date - 19,1,2020 - Time - 08:01 - Email - John.Z.Smith@yahoo.com")
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