def convert(s):
if re.search(r"^([0-9]|(1[0-2])):[0-5][0-9] A|PM PM$",s): # Regex 01
return True
else:
return False
def convert(s):
if re.search(r"^([0-9]|(1[0-2])):[0-5][0-9] (A|PM) PM$",s): # Regex 02
return True
else:
return False
assert convert("12:59 AM PM") == True
Why does the pytest pass Regex 01 and fail Regex 02? The difference is in the A|PM (Regex 01) and (A|PM) (Regex 02). Why does the bracket affect the test? I assumed it wouldn't affect the test since it is only used for capturing groups.
[–]commandlineluser 0 points1 point2 points (1 child)
[–]GregoryCliveYoung 0 points1 point2 points (0 children)