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.
| Input | Result | Matched |
|---|---|---|
| 2026-08-15 | matches | 2026-08-15 |
| 1999-12-31 | matches | 1999-12-31 |
| 2000-01-01 | matches | 2000-01-01 |
| 2026-8-15 | no match | — |
| 2026-13-01 | no match | — |
| 2026-08-32 | no match | — |
| 26-08-15 | no 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 RegexBuilderOther regex answers
- Regex for an email address
- Regex for a US phone number
- Regex for an IPv4 address
- Regex for a URL
- Regex to match digits only
- Regex for alphanumeric characters
- Regex to find special characters
- Regex for a strong password
- Regex to match whitespace
- Regex to trim leading and trailing whitespace
- Regex for a UUID
- Regex for a hex colour code