Python正则表达式大写Unicode字


问题内容

我需要找到多种语言的缩写文字。当前正则表达式为:

import regex as re
pattern = re.compile('(?:[\w]\.)+', re.UNICODE | re.MULTILINE | re.DOTALL | re.VERSION1)
pattern.findall("U.S.A. u.s.a.")

结果中不需要 美国 ,我只需要大写文本。 [AZ] 除英语外,无法使用任何语言。


问题答案:

您需要使用Unicode字符属性来匹配它们。re不支持字符属性,但是支持regex

>>> regex.findall(ur'\p{Lu}', u'ÜìÑ')
[u'\xdc', u'\xd1']