Regular expression for 12 hour time

I keep getting an error for this regex:

^((([1-9])|(1[0-2])):([0-5])(0|5)/s(A|P)M)$

It should be for a time ending in 0 or 5. So, here are some of them that should work:

  • 1:25 PM
  • 11:00 a.m.
  • 9:55 PM

But I keep getting this error message:

Internal error matching pattern '^((([1-9])|(1[0-2])):([0-5])(0|5)/s(A|P)M)$'from value'1:00 PM'

What am I doing wrong?

+3
source share
3 answers

I think you should use \ s not / s

+5
source

\ s, not/s. \s +, . , \s *. , - 09:50? 0 .

+7

I think instead of "/ s" you want "\ s", right?

+5
source

Source: https://habr.com/ru/post/1715100/


All Articles