date_re = re.compile(r'^stuff (\d\d-\d\d\s)')
date_re.search('stuff 10-18 16:51').group(1)
由于\s
而不匹配。如果我删除空白符号,该组将发现xx-xx数字模式正常。我在正则表达式中的空间做错了什么?
我的完整代码:
>>> print t
stuff 11-16 12:10, Size 1.64 GiB, ULed by
>>>date_long_re = re.compile(r'^stuff (\d\d-\d\d\s\d\d\d\d)')
>>>size_re = re.compile(r'Size \d+[.\d*]?')
>>>date_re = re.compile(r'^stuff (\d\d-\d\d\s)')
>>>date_re.search(t).group(1)
AttributeErrorTraceback (most recent call last)
<ipython-input-10-18bd3a48937c> in <module>()
3 size_re = re.compile(r'Size \d+[.\d*]?')
4 date_re = re.compile(r'^stuff(\d\d-\d\d\s)')
----> 5 date_re.search(t).group(1)
AttributeError: 'NoneType' object has no attribute 'group'
答案 0 :(得分:-2)
import unicodedata
t= unicodedata.normalize("NFKD", t)
... unicode字符串中有一个愤怒的\xa0
。