3
我甲肝一个字符串,它可以包含以下内容:Python的正则表达式:匹配一个名为组或另一个
lots of text Nov 30 2011 lots more of text
或
lots of text Nov 30 12:48 lots more of text
我想匹配的是线内的日期。我想是第一行:
{'date': 'Nov 30 2011', 'time': None}
或下联:
{'date': None, 'time': 'Nov 30 12:48'}
所以我学尝试是这样的:
re.match(
'^.+((?P<date>\w{3} \d{1,2} \d{4})|(?P<time>\w{3} \d{1,2}:\d{2})).+',
line
)
但这不工作,它返回None
。我尝试了其他一些组合,但都没有工作。
我该怎么做?