【发布时间】:2015-06-20 19:46:40
【问题描述】:
我正在尝试匹配日期格式为(月 dd,yyyy)的字符串中的日期。当我在下面使用我的正则表达式模式时,我对看到的内容感到困惑。它只匹配以日期开头的字符串。我错过了什么?
>>> p = re.compile('[A-z]{3}\s{1,}\d{1,2}[,]\s{1,}\d{4}')
>>> s = "xyz Dec 31, 2013 - Jan 4, 2014"
>>> print p.match(s).start()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'NoneType' object has no attribute 'start'
>>> s = "Dec 31, 2013 - Jan 4, 2014"
>>> print p.match(s).start()
0 #Correct
【问题讨论】: