How to match and delete any line containing a specific line?

I have a huge list of URLs from my website. Example:

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

I want to clear this list of all items /folder2in the path. I need a regex to search and replace for everything that uses /folder2/, and remove these lines from my list. So find / replace it with an empty one.

Does anyone know what the correct expression is for this? I must indicate that I am using Dreamweaver as my editor, which can use different regular expressions.

+3
source share
2 answers

This expression will match the entire line, so it will contain the string "/ folder2":

^.+?\/folder2/.+$

NTN.

+7

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()
0

Source: https://habr.com/ru/post/1787008/


All Articles