Regular Expressions 101

Extract times from a string

Open Workspace
  • PCRE (Legacy)
  • Match
1

Regular Expression

/
([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.