繁体   English   中英

如何匹配和删除包含特定字符串的任何行?

[英]How to match and remove any line containing a specific string?

我有一个庞大的网站目录列表。 例:

/folder/folder2/folder3/page.htm
/folder/folder2/folder3/page2.htm
/folder/folder2/folder3/page3.htm
/folder/folder2/folder3/page4.htm

我想清理路径中包含/folder2的所有项目的列表。 我需要一个正则表达式来执行查找和替换使用/folder2/所有内容,并从列表中删除这些行。 所以用空白查找/替换它。

有谁知道这个正确的正则表达式是什么? 我应该指定我使用Dreamweaver作为我的编辑器,它可能使用不同的正则表达式。

此表达式将匹配整行,以便在其中出现字符串“/ folder2”:

^.+?\/folder2/.+$

HTH。

在Python中将是:

import re
regex = re.compile('.*/folder2/.*')
f = open("filtered_file.txt", "w")
map(lambda x: f.write(x), filter(lambda x: not regex.match(x), open("input.txt")))
f.close()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM