我需要找到许多语言的缩写文本.目前的正则表达式是:
import regex as re
pattern = re.compile('(?:[\w]\.)+', re.UNICODE | re.MULTILINE | re.DOTALL | re.VERSION1)
pattern.findall("U.S.A. u.s.a.")
Run Code Online (Sandbox Code Playgroud)
我在结果中不需要美国,我只需要大写文本.除了英语之外,[AZ]不会使用任何语言.
Ign*_*ams 11
您需要使用Unicode字符属性才能匹配它们.re不支持字符属性,但regex确实如此.
>>> regex.findall(ur'\p{Lu}', u'ÜìÑ')
[u'\xdc', u'\xd1']
Run Code Online (Sandbox Code Playgroud)