Dates YYYY-MM-DD
A regex exercise from Regexdrill. Solve it with a pattern box with live highlighting in your browser, checked against hidden test strings, and it is checked the moment you submit.
The task
The whole line must match. Match a date written YYYY-MM-DD with a month from 01 to 12 and a day from 01 to 31. Do not worry about month lengths.
What this exercise teaches
\d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\d|3[01]) limits months to 01 to 12 and days to 01 to 31.
A hint if you get stuck
Spell out the valid ranges with alternation: a month is 0 then 1-9, or 1 then 0-2.
This exercise is part of Pro
Pro unlocks all 52 exercises, with worked solutions and progress saved to your account. The free exercises work without an account.
You create a free account first, so Pro is attached to it.
Monthly is charged today and then every month until you cancel, in one click from your account page. Lifetime is one payment with no renewals. Full refund within 14 days of paying.