为什么这个正则表达式不匹配任何日期?

Why doesn't this Regex match any of the dates?

我正在尝试使用正则表达式将数据框中的日期与 500 个条目匹配:

日期可以采用以下格式:

04/20/2009; 04/20/09; 4/20/09; 4/3/09
Mar-20-2009; Mar 20, 2009; March 20, 2009; Mar. 20, 2009; Mar 20 2009;
20 Mar 2009; 20 March 2009; 20 Mar. 2009; 20 March, 2009
Mar 20th, 2009; Mar 21st, 2009; Mar 22nd, 2009
Feb 2009; Sep 2009; Oct 2010
6/2008; 12/2009
2009; 2010

dates[dates[0].str.contains(r'(?P<year>\d?\d?\d\d)')].shape

returns shape(500,1)

的元组

但是

dates[dates[0].str.contains(r'((?P\<day\>(\d?\d)?(\s|-|/|th|st|nd)?)??P\<year\>(\d?\d?\d\d))')].shape

returns shape(0,1) 的一个元组,但是日期组是可选的,所以它不应该仍然匹配年组。

好的,我知道了。

正确的正则表达式模式是: r'((?P(\d?\d)?(\s|-|/|th|st|nd)?)?(?P\d?\d?\d\d))'

年组的括号位置错误。