Regex for Matching a 24-Hour Time (HH:MM:SS)
Matches a time string in 24-hour format with hours, minutes, and seconds.
Published October 10, 2026
This regex matches 24-hour times in HH:MM:SS format, with hours 00–23 and minutes and seconds 00–59.
How the pattern works
Breaking the pattern down: [01]\d|2[0-3] = hours 00–23; [0-5]\d = minutes/seconds 00–59.
Test your regex against both matching and non-matching inputs; use the Regex tool on this site to experiment live.
Pattern tests
/^([01]\d|2[0-3]):[0-5]\d:[0-5]\d$/
✓ '00:00:00'
✓ '23:59:59'
✓ '12:30:45'
✗ '24:00:00'
✗ '12:60:00'
Practical examples
The pattern
const re = /^([01]\d|2[0-3]):[0-5]\d:[0-5]\d$/Test it
const re = /^([01]\d|2[0-3]):[0-5]\d:[0-5]\d$/
re.test('00:00:00') // true
re.test('23:59:59') // true
re.test('24:00:00') // false
re.test('12:60:00') // falseIn Python
import re
re.search(r'^([01]\d|2[0-3]):[0-5]\d:[0-5]\d$', text)Common mistakes
- Allowing 24:00:00.
- Forgetting leading zeros.
- Time zone suffixes.
Key takeaways
- Anchors (^ and $) make the whole string match instead of a part of it.
- Regex checks format only; verify data separately when it matters.
- Test with valid and invalid samples.
FAQ
HH:MM only?
Drop the last :[0-5]\d group.
Where can I test this pattern?
Use the Regex Tester on this site, or regex101.com.