Notepad++: Comment lines with a pattern in multiple files using regex
If you ever had to comment lines in source code with a particular pattern there is an easier way to do that using regular expression in notepad++.
Open the replace dialog box using Ctrl+H
.
To comment lines with a “pattern” type ^(.*pattern.*)
in the “Find what” text box, where ^
references to the beginning of the line in which the “pattern” exists. [1]
Add comment tags //\1
in the “Replace with” text box, where \1
is a reference to the first bracketed expression. [1]
You can add any comment tags you like //
for c++ or #
for python.
Make sure you select the “Regular Expression” radio button as the “Search Mode”.
Finally, click “Replace All”
If you want to comment lines with the same pattern in multiple files you should open all the files in notepad++ and click “Replace All in All Opened Documents”.
Here I have used notepad++. You can use any other software the supports regex to accomplish the same thing.