How to delete lines in Notepad++ that contain specified text string

Have you ever had a list similar to this one:

Some text here...spam...some text here
Some text here...good...some text here
Some text here...good...some text here
Some text here...spam...some text here

…and you wanted to delete all the ones that contained a certain string of characters? If so, I have the solution!

  1. Open the file with the text you want to filter in Notepad++. If you don’t have it, google it and download it.
  2. In the top tool bar of Notepad++, click on search/replace to open up the search and replace dialog window.
  3. In the replace dialog window, where it says “find what” enter: .*spam.*
  4. That’s dot star then the text or character string you want to search for followed by another dot star. Replace the word “spam” in my example with the text you want to search for.
  5. Check the box towards the bottom left of the replace dialog window that says “Regular Expression” to enable the use of regular expression search mode.
  6. Leave the “Replace with” field blank so it deletes the lines it finds that text in and doesn’t replace it with something.
  7. Click “Replace All” to the right of the dialog window and it will replace all lines that contain spam with a blank line.

Here’s what your find and replace dialog will look like:

Snap 2014-12-15 at 12.14.49

Delete all blank lines in Notepad++

Now that you have gotten rid of the lines you didn’t want, you may also want to delete all those pesky blank lines with another search & replace trick. Here is how:

Simply go back up to the Notepad++ toolbar and navigate to “Edit/Line Operations/Remove Empty Lines” and it will quickly remove any empty lines without having to do a complicated regex which you can also do if you know how.