Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to delete all comments in a file using Notepad++?

Notepad++ obviously recognizes all comments as such. Is there a way to simply delete all?

Edit: Stat-R's bookmark method has helped greatly, not only for removing comments but for conditionally removing lines in general.

like image 853
Cos Avatar asked Jan 05 '12 19:01

Cos


3 Answers

For a general file, first of all you need to know the comment operator of the language you are writing the file in. For example, in java script the comment operator is //. For the following code...

enter image description here

In NP++, you need to

Mark the lines that contains '//'. Make sure the bookmark option is enabled.

enter image description here

Then, choose from NP++ menu Search>Bookmark>Remove Bookmarked lines

enter image description here


EDIT: Another solution after @Chris Mirno 's suggestion is as follows: Use regular expression. See the image below. It is self explanatory enter image description here

To understand it better, refer to these

like image 121
Stat-R Avatar answered Oct 04 '22 13:10

Stat-R


enter image description here

In the Find & Replace Dialog, put the following regex and adjust the search options as depicted.

/\*.*?\*/

Replace with: (empty)

Select Mode: Regular Expression AND .(dot) matches newline

This should remove all your C style comments spanned across lines.

like image 36
SenG Avatar answered Oct 04 '22 12:10

SenG


Star-R and Chris Mirno Answer are also Correct and Good.

But For Line Comment:

//.*?(?=\r?$)

Explanation:

// will be the Starting Position

.*? Will be any character

(?=\r?$) will search to the end of the line (as it is required in line comment)

Note: But Still check each of the line because for example if your code contains soap format like

//www.w3.org/2001/XMLSchema-instance\x2......");

it will capture this line because the starting is // and it goes to end of the line so watch out for this :)

like image 10
Jamil Avatar answered Oct 04 '22 14:10

Jamil