可能重复: python正则表达式中的unicode字符匹配
使用
re.findall(r'\w+', ip)在Fältskog上返回F和ltskog。我尝试了字符串和unicode,但都是一样的。结果
发布于 2012-09-22 07:01:35
您需要设置适切 标志 (在本例中,UNICODE告诉re \w是什么意思):
re.findall(r'\w+', ip, re.UNICODE)
# EDIT
Python 2.7.3 (default, Aug 1 2012, 05:16:07)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import re
>>> re.findall(r"\w+", u"Fältskog", re.UNICODE)
[u'F\xe4ltskog']
>>> 发布于 2012-09-22 07:16:41
Re.findall(r‘w+’,ip)
如果您想要更直观,也可以这样做。
https://stackoverflow.com/questions/12541546
复制相似问题