我知道有很多关于获取日期正则表达式的答案,但我试图在python中创建可读的东西。
到目前为止,我已经提出了以下建议。有人可以查看以下代码吗?
def getDateRegex():
delim = r'[/\.\- ]'
dd = r'[0-3]*[0-9](st|th|nd){0,1}' # get a better 01-31 regex
mm = r'[0-1]*[0-9]' # get a better 01-12 regex
yyORyyyy = r'(?:[0-9]{2}){1,2}'
month = r'(Jan(uary)?|Feb(ruary)?|Mar(ch)?|Apr(il)?|May|Jun(e)?|Jul(y)?|Aug(ust)?|Sep(tember)?|Oct(ober)?|Nov(ember)?|Dec(ember)?)'
mmORmonth = r'({0}|{1})'.format(mm,month)
dd_mmORmonth_yyORyyyy = delim.join([dd, mmORmonth, yyORyyyy]) # format1
yyORyyyy_mmORmonth_dd = delim.join([yyORyyyy, mmORmonth, dd]) # format2
final_regex = r'({0}|{1})'.format(dd_mmORmonth_yyORyyyy,yyORyyyy_mmORmonth_dd)
return final_regex