Advertisement

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.

The pattern
^([01][0-9]|2[0-3]):[0-5][0-9]$
Load this pattern into the tester →

How the pattern works

Test it: match & no-match examples

Every row is loaded straight into the tester — click Try to see the match live:

InputResultWhy
00:00MatchmidnightTry →
23:59Matchlast minute of dayTry →
12:30MatchnoonTry →
24:00No matchhour 24 invalidTry →
12:60No matchminute 60 invalidTry →
9:30No matchsingle-digit hour rejectedTry →

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.
Open the regex tester →

FAQ

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.