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!
- Open the file with the text you want to filter in Notepad++. If you don’t have it, google it and download it.
- In the top tool bar of Notepad++, click on search/replace to open up the search and replace dialog window.
- In the replace dialog window, where it says “find what” enter: .*spam.*
- 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.
- 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.
- Leave the “Replace with” field blank so it deletes the lines it finds that text in and doesn’t replace it with something.
- 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:
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.