import re
regex = re.compile(r"(?:(?P<EngDate>[a-zA-Z]+\s)??(?P<Date0>(?<!\.)(?:\d{1,2}(?=[,\s.\/-])|\d{4}))\.??(?(1),?)(?P<d_sep>[\s.\/-])?(?:(?P<Date1>[^\W\d_]+|\d{1,2})(?P=d_sep))?(?(1)[0-2]?\d(?::\d{2}){1,2}\s\w+\s)(?P<Date2>\d{2}|\d{4})(?!:|\d))|(?P<Time>(?<![\+-0])[0-2]?\d(?:\:[0-6]\d){1,2}(?:[,\.]\d{3,6})?)")
test_str = ("04.march.2012 9:07:00\n"
"1999-03-22T05:06:07.000\n\n"
"20150420\n"
"14 мая 2015 08:30:43\n"
"1999 03 22T05:06:07.000+01:00\n"
" \n"
"22.3.1999 5:06:07\n"
"22. March 1999\n\n\n"
"1999-03-22 5:06:07.PD\n"
"March 22, 1999\n"
"March 22 1999\n\n"
"22/3/1999 5:06:07 AM\n\n"
"Mar 22 05:06:07 CET 1999")
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