Regular Expressions 101

Community Patterns

Community Library Entry

1

Regular Expression
PCRE (PHP <7.3)

/
(^([01][0-9]|2[0-3])[:][0-5][0-9]([:][0-5][0-9])?$)|(^(([0-9])|(1[0-2])):([0-5][0-9])(:([0-5][0-9]))?\s?[ap]m$)
/
gm

Description

Matches a time in either 25Hr or 12Hr format. Seconds are optional for either format.

Submitted by anonymous - 8 years ago