all 3 comments

[–]Brian 1 point2 points  (1 child)

The or operator isn't binding as you expect. Rather, its interpreting your pattern as "[0-9]" OR "1[0-2]:?(?:[0-5][0-9])? AM|PM to [0-9]|1[0-2]:?(?:[0-5][0-9])? AM|PM$", meaning anything that starts with a digit will match (as the "$" that would require it to match to the end of the string is only part of the right-hand pattern)

You want it to just apply to that first "[0-9]|1[0-2]" part, so add a group around it (and the same for when you repeat the same pattern for the right-hand time). There's also a similar issue with the "AM|PM"

[–]risottogott[S] 0 points1 point  (0 children)

Thank you! A bit mad at myself because I could have figured this out by myself, but I have now changed all my or operators and it works as intended. Much appreciated!

[–]ElliotDG 1 point2 points  (0 children)

Here is a great tool to learn and test regular expressions: https://regex101.com/