RRegexBuilder
Get RegexBuilder

RegexBuilder · regex answers

Regex for a date in YYYY-MM-DD format

/^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$/

This checks the shape and the obvious ranges: month 01-12, day 01-31. It cannot check that the day exists in that month — 2026-02-31 passes, and so does 2025-02-29. Calendar validity needs a date library, not a pattern.

What each part does

\d{4}four-digit year
0[1-9]|1[0-2]month 01 through 12, leading zero required
0[1-9]|[12]\d|3[01]day 01 through 31

Tested against real input

Every row below was run through the engine when this page was built. The third column is the substring the pattern actually matched.

InputResultMatched
2026-08-15matches2026-08-15
1999-12-31matches1999-12-31
2000-01-01matches2000-01-01
2026-8-15no match
2026-13-01no match
2026-08-32no match
26-08-15no match

The mistake to avoid

Believing it validated the date. A regex that accepts 2026-02-31 has checked formatting only — parse the string afterwards and compare it back.

Try it on your own text

Paste this pattern and your input, see each match highlighted with its capture groups, step through what the engine did, and get the equivalent syntax for JavaScript, Python, Java, Go and PCRE.

Open RegexBuilder

Other regex answers