import re
regex = re.compile(r"^(0\d:[0-5]\d)|(^1[01]:[0-5]\d)|(^12:[0-2]\d)|(^12:3[0-5])", flags=re.MULTILINE)
test_str = ("00:00\n"
"01:00\n"
"02:00\n"
"03:00\n"
"04:00\n"
"05:00\n"
"06:00\n"
"07:00\n"
"08:00\n"
"09:00\n"
"10:00\n"
"11:00\n"
"12:00\n"
"12:09\n"
"12:19\n"
"12:29\n"
"12:30\n"
"12:31\n"
"12:32\n"
"12:33\n"
"12:34 \n"
"12:35 midday (all days of week)\n"
"12:36\n"
"13:00\n"
"14:00\n"
"15:00\n"
"16:00\n"
"17:00\n"
"18:00\n"
"19:00\n"
"19:35 evening (sun-fri)\n"
"20:00\n"
"20:05 evening (saturday)\n"
"21:00\n"
"22:00\n"
"23:00")
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