10

I am looking for a notepad++ regexp that contains a specific string. I then want to delete this whole line.

1
  • Make the regexp match the beginning of a line through the \n or \r\n at the ends of them (depending on the convention being used), and them make the replacement string nothing.
    – martineau
    Jan 25, 2011 at 12:05

4 Answers 4

22

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. ;)

2
  • Do you mean he should do notepad++'s REPLACE ALL then. ok
    – barlop
    Feb 28, 2014 at 12:10
  • See answer below: Ensure matches newline option is unchecked. Jan 29, 2023 at 13:23
3

Make sure that you are unchecking the option .matches newline.

enter image description here

2

To find multiple strings on the same line you can use ^.\*(string).\*(string).*$

2

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .