//g
  • 100% Free
  • No Sign-Up
  • No Credit Card
  • No Free Trial
  • No Pro Tier
  • No Watermarks

Nothing is uploaded. Just open it and start.

24-Hour Time Regex

A 24-hour time as HH:MM, with optional seconds.

/^(?:[01]\d|2[0-3]):[0-5]\d(?::[0-5]\d)?$/

Piece by piece

  1. ^the start of the text
  2. (?:a group (not captured)
  3. [01]one of “0”, “1”
  4. \da digit (0–9)
  5. |or
  6. 2the character “2”
  7. [0-3]one of 0–3
  8. )end of the group
  9. :the character “:”
  10. [0-5]one of 0–5
  11. \da digit (0–9)
  12. (?:a group (not captured)
  13. :the character “:”
  14. [0-5]one of 0–5
  15. \da digit (0–9)
  16. )?end of the group, repeated optionally (0 or 1 time), as many as possible
  17. $the end of the text

Examples

TextResult
00:00Matches
23:59Matches
09:30:15Matches
24:00Doesn't match
9:30Doesn't match
12:60Doesn't match
12:30:60Doesn't match
  • Leap seconds (23:59:60) don't match.

Other common patterns

Test any regular expression →

Frequently asked questions

How do I use this time (24-hour) regex in JavaScript?
Write it as /^(?:[01]\d|2[0-3]):[0-5]\d(?::[0-5]\d)?$/ and call re.test(text). It is anchored with ^ and $, so it checks the whole text; remove them to find it inside longer text (and add the g flag to find every one). The Code view writes it out for Python, Go and PHP too.
Is it a complete validator?
No regex is the whole story. Leap seconds (23:59:60) don't match.
Can I try it on my own text?
Yes. The tester above already holds the examples; paste your own text over them and every match is highlighted as you type. Nothing is uploaded.

Spotted a bug or have a suggestion?

Found something broken, have an idea, or just want to say thanks about any of our tools? Every message reaches a real person.