Regular Expressions 101

Community Patterns

Community Library Entry

0

Regular Expression
PCRE2 (PHP >=7.3)

/
(?:[0-9]|1[0-2]):[0-5][0-9]\s(?:am|pm)|(?:[0-1][0-9]|2[0-3]):[0-5][0-9]
/
gm

Description

This regex finds the substrings of the formats: hh:mm (0 <= hh <= 23; 0 <= mm <= 59) or h:mm am|pm (0 <= 12; 0 <= mm <= 59)

Submitted by anonymous - 3 years ago