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)