I'm trying to delete all punctuation from a text using regex. The problem is, punctuation regex doesn't seem to have any effect (neither \p{P} nor \p{Punct}).
import re
hello_world = 'Hello, world!'
hello_world = re.sub('\p{Punct}', '', hello_world)
print(hello_world)
Am I doing something wrong? The following produces the desired effect, but I still don't get why the code above doesn't work.
# import string
# ...
hello_world = re.sub('[{}]'.format(string.punctuation), '', hello_world)
stdlib's re module does not support specifying properties (\p{}). There is regex module that does support the properties and it is a drop-in replacement for the re module.
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