Regular Expressions 101

Community Patterns

get-time

0

Regular Expression
PCRE2 (PHP >=7.3)

/
^([0-9]|1[0-2]):[0-5][0-9][ ]?([AP]M|[ap]m)
/
gm

Description

Suggest a RegEx to checks for the time format of a 12-hour clock, as follows: the hour is between 1 and 12, with no leading zero, followed by a colon, then minutes between 00 and 59, then an optional space, and then AM or PM, in upper or lower case

Submitted by ali - a year ago