Python3 正则处理特殊字符
import re
# 测试文本
content = '<h1>你好</h1>666*Notice*\toh\rsee\ngood '
def clear_special_char(content):
'''
正则处理特殊字符
:param content:原文本
:return: 清除后的文本
'''
s = re.sub(r"</?(.+?)>| |\t|\r", "", content)
s = re.sub(r"\n", " ", s)
s = re.sub(r"\*", "\\*", s)
return s
# 调用
print(clear_special_char(s))
# 打印结果:你好666\*Notice\*ohsee good