Skip to main content
 首页 » 编程设计

python之正则表达式获取所有字母字符

2025年05月04日88JustinYoung

我想要类似 [A-z] 的东西这对所有字母字符以及 ö 之类的东西都很重要, ä , ü

如果我这样做 [A-ü]我得到可能所有拉丁语言使用的特殊字符,但它也允许其他东西,如¿¿]|{}[¢§øæ¬°µ©¥

示例:https://regex101.com/r/tN9gA5/2

编辑: 我在 python2 中需要这个。

请您参考如下方法:

根据您使用的正则表达式引擎,您可以使用 ^\p{L}+$ 正则表达式。 \p{L} 表示一个 unicode 字母:

In addition to complications, Unicode also brings new possibilities. One is that each Unicode character belongs to a certain category. You can match a single character belonging to the "letter" category with \p{L}

Source

This例子应该说明我在说什么。 Regex101 上的正则表达式引擎似乎支持这个,你只需要从左上角选择 PCRE (PHP)。