12-hour times with AM or PM
A regex exercise from Regexdrill. Solve it with a pattern box with live highlighting in your browser, checked against hidden test strings, and it is checked the moment you submit.
The task
The whole line must match. Match an hour from 1 to 12 with no leading zero, a colon, two-digit minutes, an optional space and AM or PM in capitals.
What this exercise teaches
(?:[1-9]|1[0-2]):[0-5]\d ?(?:AM|PM) refuses 13, 0 and 09 as hours.
A hint if you get stuck
Hours are a single digit 1 to 9, or 1 followed by 0 to 2.
This exercise is part of Pro
Pro unlocks all 52 exercises, with worked solutions and progress saved to your account. The free exercises work without an account.
You create a free account first, so Pro is attached to it.
Monthly is charged today and then every month until you cancel, in one click from your account page. Lifetime is one payment with no renewals. Full refund within 14 days of paying.