Pattern library / Dates & Time
Regex to Match 12-Hour Clock Times (HH:MM AM/PM)
Validates HH:MM AM/PM with hour 01-12 and minute 00-59. Case-insensitive AM/PM.
How the pattern works
(0?[1-9]|1[0-2])— hour 1-12 (leading zero optional).[0-5][0-9]— minute 00-59.\s?(AM|PM|am|pm)— optional space + AM/PM.- Drop the suffix to make AM/PM optional, or require it strictly by removing
?.
Test it: match & no-match examples
Every row is loaded straight into the tester — click Try to see the match live:
| Input | Result | Why | |
|---|---|---|---|
9:30 AM | Match | morning time | Try → |
12:00 PM | Match | noon | Try → |
11:59 pm | Match | lowercase pm | Try → |
00:30 AM | No match | hour 00 invalid in 12h | Try → |
13:00 PM | No match | hour 13 invalid | Try → |
9:60 AM | No match | minute 60 invalid | Try → |
Where to use it
JavaScript
const re = /^(0?[1-9]|1[0-2]):[0-5][0-9]\s?(AM|PM|am|pm)$/i;
re.test('9:30 AM'); // true
Python
import re re.match(r'^(0?[1-9]|1[0-2]):[0-5][0-9]\s?(AM|PM|am|pm)$', '9:30 AM', re.I)
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.