簡體   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