notepad++ regexp to find all lines which contain a specific string
I am looking for a notepad++ regexp that contains a specific string. I then want to delete this whole line.
Well I don't think you can do it with one search-replace.
I'd do this.
Open up the search-replace, choose mode regex and search for:
^.*(string).*$
and let the replacement be \1 (this is the string marking the lines you don't want). This will leave lines with only the unwanted string and nothing else.
Then switch to the extended search and search for \r\nstring
and leave the replacement blank. This will delete the lines with only the unwanted string in it.
There's probably a neater way to do it but this works.
Edit: and oh, check the first line of the document too for a line with only the unwanted string as this will miss those. As said, there's probably a better way. ;)
Make sure that you are unchecking the option .matches newline
.
So, I wanted to delete an entire line if it contained one of three words: LAB,RAD,TRAN. So what I did was a "find and replace" in Notepad++ where I match the whole line if it contains one of these words. Additionally though I have it match the new line (\n) and return carriage (\r) characters and replaced the whole thing blank (e.i. nothing). That way when it does the replace it remove all the text including the hidden characters that give you a new line. This made it so it didn't leave a blank line after replacement
REGEX:
.*((LAB)|(RAD)|(TRAN)).*\r\n
To find multiple strings on the same line you can use ^.\*(string).\*(string).*$