正则表达式不喜欢国际字符

2024-10-04 09:25:16 发布

您现在位置:Python中文网/ 问答频道 /正文

Possible Duplicate:
matching unicode characters in python regular expressions

使用

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

on Fältskog返回F和{}。我试过使用字符串和unicode,但都是一样的。结果


Tags: 字符串inipreonunicodeexpressionsmatching
2条回答

您需要设置appropriateflags(在本例中,^{}告诉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']
>>> 

在关于芬德尔(r'[å2019;Ä201; \w]+',ip)

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

相关问题 更多 >