How do you match 12 hour time hh:mm in a regex?

前端 未结 11 991
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-03 01:48

How could you match 12 hour time in a regex-- in other words match 12:30 but not 14:74? Thanks!

11条回答
  •  感情败类
    2021-01-03 02:33

    (0?\d|1[0-2]):([0-5]\d)
    

    That will match everything from 0:00 up to 12:59. That's 13 hours, by the way. If you don't want to match 0:00 - 0:59, try this instead:

    ([1-9]|1[0-2]):([0-5]\d)
    

提交回复
热议问题