python正则表达式中[:alpha:]的简写

hje*_*mig 3 python regex unicode

[:alpha:]如果我正在制作需要它的unicode正则表达式,那相当于什么.

例如,[:word:]它是[\w]

如果我得到一些帮助,将会很棒.

Tim*_*ker 10

对于Unicode合规性,您需要使用

regex = re.compile(r"[^\W\d_]", re.UNICODE)
Run Code Online (Sandbox Code Playgroud)

\p{L}当前的Python正则表达式引擎不支持Unicode字符属性(如).

说明:

\w 匹配(如果设置了Unicode标志)任何字母,数字或下划线.

[^\W] 匹配相同的东西,但对于否定的字符类,我们现在可以减去我们不想要包含的字符:

[^\W\d_]匹配任何\w匹配,但没有数字(\d)或下划线(_).

>>> import re
>>> regex = re.compile(r"[^\W\d_]", re.UNICODE)
>>> regex.findall("aä12_")
['a', 'ä']
Run Code Online (Sandbox Code Playgroud)