Dates & Timesflags: g
ISO 8601 Date
Match dates in ISO 8601 format: YYYY-MM-DD with valid month (01–12) and day (01–31) ranges.
Try it in RegexProPattern
regexJavaScript
/\d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\d|3[01])/gRaw source: \d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\d|3[01])
How it works
Year is any 4-digit number. Month uses alternation to enforce 01-12. Day enforces 01-31, though it won't catch month-specific overflows (e.g. Feb 30).
Examples
Input
2024-01-15Matches
2024-01-15
Input
1999-12-31Matches
1999-12-31
Input
2024-13-01No match
—Common use cases
- Log file timestamp extraction
- API response date validation
- Database query parsing
- Data migration scripts