0

可能重复:
在 python 正则表达式中匹配 unicode 字符

使用

re.findall(r'\w+', ip)

Fältskog回报Fltskog。我尝试使用字符串和 unicode 但相同。结果

4

2 回答 2

5

您需要设置适当的 标志(在这种情况下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-22T07:01:35.450 回答
0

re.findall(r'[åäöÅÄÖ\w]+', ip)

如果您想更直观,也可以这样做。

于 2012-09-22T07:16:41.280 回答