假设我有一个字符串
s = "Hey, {customer_name}, what's up?"
除去下划线和花括号以外的所有标点符号的合适正则表达式是什么?
答案 0 :(得分:1)
您可以将re.sub
与模式[^\w _{}]
一起使用,该模式将忽略所有字母数字字符,但将包括下划线_
和花括号{}
import re
s = "Hey, {customer_name}, what's up?"
print(re.sub(r'[^\w {}]','',s))
输出为Hey {customer_name} whats up