python 去除字符串里所有标点符号

import re
text = " Hello,. [world]!  ()!"
#r='[’!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~]+'
r='[’!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~\n。!,]+'
line=re.sub(r,'',text)

print(line)
 Hello world
posted @ 2022-08-19 22:52  luoganttcc  阅读(154)  评论(0编辑  收藏  举报