首页 > 解决方案 > 从具有匹配模式的文档中删除某些句子

问题描述

我有文本文档

text = 'This is a follow-up to your previous request #16302 "asdkjc!!!"\n\nHello asd,\n\nSo I\'ve just received the check and a signed letter from the asc acs, .....'

我想This is a follow-up to your previous request #16302 "asdkjc!!!"从文档中删除。

我试过了 :

re.sub(r'this is a follow-up to your previous request #[0-9] ["](.*?)["]', " ", text)

这无法删除。

标签: pythonregex

解决方案


你可以使用:

re.sub(r'This is a follow-up to your previous request #[0-9]+ ["](.*?)["]', " ", text)

输出:

" \n\nHello asd,\n\nSo I've just received the check and a signed letter from the asc acs, ....."

推荐阅读