Pattern library / Dates & Time
Strict Regex for 24-Hour Clock Times (HH:MM)
Stricter than the basic time regex: enforces hour 00-23 and minute 00-59. No AM/PM — 24-hour format only.
How the pattern works
[01][0-9]— hours 00-19.2[0-3]— hours 20-23.[0-5][0-9]— minutes 00-59.- Add
(:[0-5][0-9])?for optional seconds.
Test it: match & no-match examples
Every row is loaded straight into the tester — click Try to see the match live:
| Input | Result | Why | |
|---|---|---|---|
00:00 | Match | midnight | Try → |
23:59 | Match | last minute of day | Try → |
12:30 | Match | noon | Try → |
24:00 | No match | hour 24 invalid | Try → |
12:60 | No match | minute 60 invalid | Try → |
9:30 | No match | single-digit hour rejected | Try → |
Where to use it
JavaScript
const re = /^([01][0-9]|2[0-3]):[0-5][0-9]$/;
re.test('23:59'); // true
Python
import re re.match(r'^([01][0-9]|2[0-3]):[0-5][0-9]$', '23:59')
Common mistakes
Test this pattern on your own data
Paste it into the free tester with your real strings — nothing leaves your browser.
FAQ
Related patterns
For GA4-specific patterns, see the GA4 regex cheat sheet, the page path regex guide, the event filter regex guide, the GA4 regex match types, the custom channel grouping guide and RE2 vs PCRE. Browse the full regex pattern library.