Regex for a YYYY-MM-DD Date
Copy the pattern, paste your text below, and see every ISO date it finds. Below the tester: how it validates month and day ranges, and where its limits are.
What this pattern matches
This expression matches four-digit-year ISO dates in YYYY-MM-DD form, and rejects impossible months (00, 13+) and impossible days (00, 32+).
How it works, part by part
\b\d{4}- — a four-digit year on a word boundary, then a hyphen.
(?:0[1-9]|1[0-2]) — the month: 01–09 or 10–12.
(?:0[1-9]|[12]\d|3[01]) — the day: 01–09, 10–29, or 30–31.
A note on real calendars
This checks the shape, not the calendar. It cannot know that February has no 30th, or which years are leap years. If you need true date validity, parse the match with a date library after the regex confirms the format.
FAQ
Does it reject 2026-13-01?
Yes. The month group only allows 01–12, so month 13 will not match.
Will 2026-02-30 match?
Yes — the pattern only validates the shape and day range 01–31. February's real length needs a date library to check.
How do I match slash dates like 2026/09/10 too?
Replace the two hyphens with a character class [-/] so both separators are accepted.