python - What is regex for currency symbol? -
in java can use regex : \p{sc} detecting currency symbol in text. equivalent in python?
you can use unicode category if use regex package:
>>> 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] ¢ update
alterantive way using unicodedata.category:
>>> import unicodedata >>> [ch ch in '$99.99 / €77' if unicodedata.category(ch) == 'sc'] ['$', '€']
Comments
Post a Comment