Python标点正则表达式似乎不起作用

sho*_*qie 3 python regex

我正在尝试使用正则表达式删除文本中的所有标点符号.问题是,标点符号正则表达式似乎没有任何影响(既不是\p{P}也没有\p{Punct}).

import re

hello_world = 'Hello, world!'
hello_world = re.sub('\p{Punct}', '', hello_world)
print(hello_world)
Run Code Online (Sandbox Code Playgroud)

难道我做错了什么?以下产生了预期的效果,但我仍然不明白为什么上面的代码不起作用.

# import string

# ...

hello_world = re.sub('[{}]'.format(string.punctuation), '', hello_world)
Run Code Online (Sandbox Code Playgroud)

jfs*_*jfs 5

stdlib的re模块不支持指定properties(\p{}).有一个regex模块支持属性,它是re模块的替代品.