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

前端 未结 11 943
爱一瞬间的悲伤
爱一瞬间的悲伤 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:27

    You could use this one:

    /((?:1[0-2])|(?:0?[0-9])):([0-5][0-9]) ?([ap]m)/
    
    /1 => hour
    /2 => minute
    /3 => am/pm
    

提交回复
热议问题