Regular Expressions 101

Community Patterns

Community Library Entry

0

Regular Expression
PCRE2 (PHP >=7.3)

/
^[1-9][0-2]*:[0-5][0-9]*[ ]*[am|pm]*$
/
gmi

Description

The get-time regex 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 anonymous - 2 years ago (Last modified 2 years ago)