Dates & Times
Match a 24-hour time
Match times like 09:30 or 23:59:59 in 24-hour format.
Pattern
Regular expression
(?:[01]\d|2[0-3]):[0-5]\d(?::[0-5]\d)?How it works
Hours 00–23, minutes 00–59, seconds optional but if present also 00–59. Handles both `HH:MM` and `HH:MM:SS` shapes.
Matches
- ▸00:00
- ▸09:30
- ▸23:59:59
Non-matches
- ▸24:00 (invalid hour)
- ▸09:60 (invalid minute)
- ▸9:30 (missing leading zero)
Language snippets
JavaScript
const re = /(?:[01]\d|2[0-3]):[0-5]\d(?::[0-5]\d)?/g;Python
re.findall(r"(?:[01]\d|2[0-3]):[0-5]\d(?::[0-5]\d)?", text)Go
re := regexp.MustCompile(`(?:[01]\d|2[0-3]):[0-5]\d(?::[0-5]\d)?`)Java
Pattern.compile("(?:[01]\\d|2[0-3]):[0-5]\\d(?::[0-5]\\d)?")