查找文本文档中的关键字所在的句子,替换为空白

import re
filename = "1.txt"
filename_new = '3.txt'
with open(filename,"r",encoding='utf-8') as f:
    data = f.read()
    data_re = re.sub('(威信|微鑫)','微信',data)
    data_re = re.sub('微信公众号,','微信号,',data_re)
    data_re = re.sub('[\u4e00-\u9fa5]*"hongcha866"微信号,','',data_re)
    data_re = re.sub('[\u4e00-\u9fa5]*"songshu566"微信号,','',data_re)
    data_re = re.sub('[\u4e00-\u9fa5]*"xinwu799"微信号,','',data_re)
    data_re = re.sub('网址:https://[\S]+','',data_re)
    data_re = re.sub('看更多好看的小说!','',data_re)
    data_re = re.sub('-->>(本章未完,请点击下一页继续阅读)','',data_re)
    with open(filename_new,"w",encoding='utf-8') as f:
        f.write(data_re)
上一篇:Python模块之re - 正则表达式


下一篇:解决tensor.sub_(mean).div_(std)RuntimeError: output with shape [1, 28, 28] doesn‘t match the broadcas