Regex to Match 24-Hour Time (HH:MM)
Copy the pattern, paste your text below, and see every 24-hour time it finds. Below the tester: how the hour and minute ranges are bounded.
What this pattern matches
This matches a 24-hour clock time from 00:00 to 23:59, and optionally a seconds field, rejecting impossible values like 24:00 or 12:60.
How it works, part by part
(?:[01]\d|2[0-3]) — the hour: 00–19 or 20–23.
:[0-5]\d — a colon and the minutes 00–59.
(?::[0-5]\d)? — an optional colon and seconds 00–59.
\b — word boundaries so it does not match inside a longer number.
12-hour clocks
This is for 24-hour time. For a 12-hour clock with AM/PM, use (?:0?[1-9]|1[0-2]):[0-5]\d\s?(?:AM|PM) instead.
FAQ
Does it reject 24:00?
Yes. The hour group caps at 23, so 24:00 will not match.
Are seconds required?
No. The seconds group is optional, so both 09:30 and 09:30:15 match.
How do I match 12-hour AM/PM times?
Use a 1–12 hour group and add \s?(?:AM|PM) at the end; see the note above.