Advertisement

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.

The pattern
^(0?[1-9]|1[0-2]):[0-5][0-9]\s?(AM|PM|am|pm)$
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
9:30 AMMatchmorning timeTry →
12:00 PMMatchnoonTry →
11:59 pmMatchlowercase pmTry →
00:30 AMNo matchhour 00 invalid in 12hTry →
13:00 PMNo matchhour 13 invalidTry →
9:60 AMNo matchminute 60 invalidTry →

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.
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.