Delete text rows using regular expressions

Delete text rows using regular expressions

by flandersen


Posted on February 20, 2019


This tip is useful if you work with text files (e.g. log files, CSV files …) and want to delete rows containing specific keywords or patterns. Using any program that supports Regular Expressions (short regex) makes this job pretty easy.

Delete rows containing keyword/pattern:

Regex:   ^.*keyword.*$
Replace: <empty string>

Delete rows NOT containing keyword/pattern:

Regex:   ^(?!.*keyword.*).+$
Replace: <empty string>

Read more for an example with Notepad++.

  1. Start Notepad++.
  2. Load file to be edited.
  3. Press CTRL + F to open the “Replace” dialog.
  4. Configure dialog as shown below and click “Replace all”.

If something went wrong, Notepad++ lets you undo action with CTRL + Z.

Deleting rows using Notepad++ and Regex