Python uppercase text expression

I need to find abbreviations in many languages. Current regex :

import regex as re pattern = re.compile('(?:[\w]\.)+', re.UNICODE | re.MULTILINE | re.DOTALL | re.VERSION1) pattern.findall("USA usa") 

I don't need usa as a result, I only need uppercase text. [AZ] will not work in any language other than English.

+4
source share
1 answer

To match them, you need to use the Unicode character property. re does not support character properties, but regex does.

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

Source: https://habr.com/ru/post/1436267/


All Articles