python文本处理简例—删除文本中的指定字符
内联代码片
import re
def remove_char(string,char):
pattern = f"[{char}]+"
result = re.sub(pattern,'',string)
return result
ins = "两岸猿声啼不住,轻舟已过万重山"
remove_chars=['不','万']
for c in remove_chars:
ins=remove_char(ins,c)
print(ins)