24-Hour Time
Match 24-hour time formats HH:MM or HH:MM:SS with valid hour (00–23) and minute/second (00–59) ranges.
Try it in RegexPro →Available in
JavaScript / ECMAScript code
const re = new RegExp("(?:[01]\\d|2[0-3]):[0-5]\\d(?::[0-5]\\d)?", "g");
const input = "14:30";
const matches = [...input.matchAll(re)];
console.log(matches.map(m => m[0]));Uses `String.prototype.matchAll` for global iteration (Node 12+ / all modern browsers).
Python (re) code
import re
pattern = re.compile(r"(?:[01]\d|2[0-3]):[0-5]\d(?::[0-5]\d)?")
input_text = "14:30"
for m in pattern.finditer(input_text):
print(m.group(0))Stdlib `re` module — no third-party dependency. Works on Python 3.6+.
Go (RE2) code
package main
import (
"fmt"
"regexp"
)
func main() {
re := regexp.MustCompile(`(?:[01]\d|2[0-3]):[0-5]\d(?::[0-5]\d)?`)
input := `14:30`
for _, match := range re.FindAllString(input, -1) {
fmt.Println(match)
}
}Uses `regexp.MustCompile` (panics on bad patterns at startup) and `FindAllString` for all matches.
Pattern
(?:[01]\d|2[0-3]):[0-5]\d(?::[0-5]\d)? (flags: g)Raw source: (?:[01]\d|2[0-3]):[0-5]\d(?::[0-5]\d)?
How it works
Examples
Input
14:30Matches
14:30
Input
23:59:59Matches
23:59:59
Input
25:00No match
—Common use cases
- •Log timestamp extraction
- •Scheduling input validation
- •Transit/flight time parsing
- •Analytics time-bucket aggregation
Related patterns
12-Hour Time with AM/PM
Dates & TimesMatch 12-hour time formats with AM or PM suffix — e.g. 9:30 AM, 11:45:15 pm.
European Date Format (DD/MM/YYYY)
Dates & TimesMatch European-style dates in DD/MM/YYYY format with valid day (01–31) and month (01–12) ranges.
ISO 8601 Date
Dates & TimesMatch dates in ISO 8601 format: YYYY-MM-DD with valid month (01–12) and day (01–31) ranges.
ISO 8601 Date-Time
Dates & TimesMatch full ISO 8601 date-times with timezone offset or Z suffix (e.g. 2024-01-15T14:30:00Z).