import re
regex = re.compile(r"^-?(((([0][0-9])|([1][0-3])):(([03][0])|([14][5])))|14:00)", flags=re.MULTILINE)
test_str = ("00:00\n"
"01:00\n"
"00:15\n"
"00:30\n"
"00:45\n"
"01:30\n"
"04:00\n"
"05:00\n"
"06:30\n"
"10:00\n"
"13:00\n"
"14:00\n"
"13:30\n"
"14:30\n"
"20:00\n"
"24:00\n"
"-14:00\n"
"-13:30\n"
"-10:00\n"
"-09:00\n"
"-00:00\n"
"00:10\n"
"00:20\n"
"00:25:\n"
"00:35")
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