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

后端 未结 9 2060
清歌不尽
清歌不尽 2020-12-13 04:40

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 on

相关标签:
9条回答
  • 2020-12-13 05:38

    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.

    0 讨论(0)
  • 2020-12-13 05:38

    Warning to all using Stat-R's solution:
    This method will remove lines of code if formatted like this:

    echo "hello"; //This comment will be detected
    

    Following his method, the entire line will be removed. Therefore make sure to go through and make these comments, their own line before doing this method.

    0 讨论(0)
  • 2020-12-13 05:40

    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 :)

    0 讨论(0)
提交回复
热议问题