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

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)
posted @ 2021-12-18 20:48  yxmichael  阅读(362)  评论(0编辑  收藏  举报