How to replace or remove lines with REGEX in Notepad++
Notepad++ is a practical text editor that is used by many Computer Science & IT professionals. You can download Notepad++ here.
I had a student that asked how to remove ‘commented’ lines from an Avaya configuration file (46xxsettings.txt) using a Regular Expression (REGEX), and Notepad++ (that is to say, delete any lines that began with a # character). I thought this was a practical enough trick to post on my blog, as you can tweak this simple REGEX string to remove, or modify, any lines from any text file you might be interested in manipulating.
1) Open the file you wish to manipulate in Notepad++
2) Click on ‘Search’
3) Click on ‘Find’
4) Click the tab ‘Replace’
5) In the “Find What:” textbox type this ^[#].*
NOTE: What you just created is a REGEX string. It is read, “Any parsed strings that begin with a # are a match, regardless of how long those strings are, or what they contain”. You can manipulate this search string by replacing the # character with other characters (such as ;).
6) in the “Replace:” textbox type NOTHING (as in, leave it blank)
7) Press the “Replace All” button
8) Click “File”
9) Click “Save As…”
10) Save your new file as something OTHER than the current file name (so you don’t lose the original file).