Regular Expressions 101

Community Patterns

Match time in mm:ss, or hh:mm:ss if `hh > 00`

0

Regular Expression
ECMAScript (JavaScript)

/
(((0[1-9])|[^0]\d):)?[0-5]\d:[0-5]\d$
/
gm

Description

Matches time strings formatted as mm:ss or hh:mm:ss under the following conditions:

  • mm:ss: only if mm and ss are less than 60
  • hh:mm:ss: the above condition applies, but it selects hours only if hh is greater than 00
Submitted by Liddack - 6 years ago