关注者
0
被浏览
174
1 个回答
-
如果使用
regex
包,则可以使用unicode类别:>>> import regex >>> regex.findall(r'\p{Sc}', '$99.99 / €77') # Python 3.x ['$', '€']
>>> regex.findall(ur'\p{Sc}', u'$99.99 / €77') # Python 2.x (NoteL unicode literal) [u'$', u'\xa2'] >>> print _[1] ¢
更新
交替使用方式
unicodedata.category
:>>> import unicodedata >>> [ch for ch in '$99.99 / €77' if unicodedata.category(ch) == 'Sc'] ['$', '€']