I want to match 1900-01-01 to 2099-12-31 in each of these formats:
YYYY
YYYY-MM
YYYY-MM-DD
This is my current solution:
^(19|20)[0-9]{1}[0-9]{1}-?([0,1]{0,1}[0-2]{0,1}){0,1}-?([0-3]{0,1}[0-9]{0,1}){0,1}
But my solution has at least 4 critical bugs which I'm not able to fix:
1921-00
matches successfullyThere is no restriction "Only 1 of 2 digits in month or date can be 0, but not both of them" in my solution
1921-
matches successfullyThere is no restriction "The last symbol of the date can be only digit, not hyphen" in my solution
1921-1
matches successfullyThere is no restriction "Month and date may contain only 0 or 2 digits, not 1 digit" in my solution
And the main:
1921-22
matches successfullyThere is no restriction "Date can't exist without month" in my solution
I'm using Python (if it matters). I'll be very grateful for help with adding this restrictions to my solution.