+ -
当前位置:首页 → 问答吧 → 请教正则表达式匹配中文的问题

请教正则表达式匹配中文的问题

时间:2011-07-07

来源:互联网

大家帮我解释一下为什么没法匹配上中文啊?
>>> import re
>>> mathchObject=re.compile(r"(?P<aa>\w+).*")
>>> m=mathchObject.match("啊")
>>> print m
None
>>> print m.groupdict()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'NoneType' object has no attribute 'groupdict'

>>> m=mathchObject.match("sss")               
>>> print m.groupdict()
{'aa': 'sss'}

作者: airtobreath   发布时间: 2011-07-07

(?P<aa>\w+).* 改成 (?P<aa>\w+.*)

作者: flying_away   发布时间: 2011-07-07

回复 flying_away


    这样子改不行

作者: airtobreath   发布时间: 2011-07-07