Regular Expressions 101

Community Patterns

Extract times from a string

1

Regular Expression
PCRE (PHP <7.3)

/
([0-9]{1,2}:?(?:[0-9]{2})?)-([0-9]{1,2}:?(?:[0-9]{2})?)\s(AM|PM)
/
ig

Description

I use this to extract and later calculate the difference between two times.

Submitted by Ernie C. - 9 years ago