I installed the module regex (not re!) for Python 3.4.3 solely to be able to use POSIX classes such as [:graph:]. However, these don't seem to work.
import regex
sentence = "I like math, I divided ÷ the power ³ by ¾"
sentence = regex.sub("[^[:graph:]\s]","",sentence)
print(sentence)
Output: I like math, I divided ÷ the power ³ by ¾
Expected output: I like math, I divided the power by
It does work in PCRE though. So what am I missing here?
try sentence = regex.sub("[^[:graph:]\s]","",sentence,flags=regex.VERSION1)
You need to add flag regex.VERSION1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With