I use python regex to match dates on forms: 1999-01-01 or 1999.1.1 or 1999-1-1. but not the same as 1999.1-1 or 1999-1.1.ie, the signs between the annual month and the day must be consecutive. For this, I use the following code, which is messy. Is there a better way to do this?
import regex as re
re.fullmatch('(((((19|20)\d\d-(([1-9])|((0[1-9]|1[012])))-(?p)([1-9]|(0[1-9]|[12][0-9]|3[01]))(\.)?))))|' \
'(((((19|20)\d\d\/(([1-9])|((0[1-9]|1[012])))/(?p)([1-9]|(0[1-9]|[12][0-9]|3[01]))(\.)?))))|'\
'(((((19|20)\d\d\.(([1-9])|((0[1-9]|1[012])))\.(?p)([1-9]|(0[1-9]|[12][0-9]|3[01]))(\.)?))))','1999.1.1')
source
share