Notepad++ multiline regex

后端 未结 4 781
梦如初夏
梦如初夏 2020-12-10 11:06

I\'ve got hundreds of files of the type linked here: http://pastebin.com/fGgLfZf8

But I want to remove all the comments that occupies more than one line eg.

相关标签:
4条回答
  • 2020-12-10 11:43

    <!--[*a-zA-Z\r\n]*-->

    this one seems to only take multi-line comments in notepad++

    Edit: little mistake : spaces are a problem with this one. You can try <!--[\r\n]{1}[* a-zA-Z\r\n]*-->

    0 讨论(0)
  • 2020-12-10 11:54

    This expression <!--.+?(?<=[\*\r\n])--> matched the multi-line comments only in Notepad++ as well.

    0 讨论(0)
  • 2020-12-10 11:56

    Next to the "Regular expression" selection in "Search Mode" there is a "matches newline" checkbox (according to @glatapoui it should be noted that this only works in Notepad++ v6, not in previous versions).

    enter image description here

    0 讨论(0)
  • 2020-12-10 12:02

    Another way to catch multi-line text is use the expression:

    <!---([\S\s]+?)--->
    

    \S+ matches all no-space symbols,
    \s+ matches all space symbols (including \r \n \t).

    It works for notepad++, maybe, otherwise too...

    EDIT: At the first look I didn’t noticed that problem issue is catch and delete only multiline comments excluding monoline ones. I found method of two iterations. First we need to find and replace by nothing following text

    <!—-(?:(?!.*—->)[\s\S]+?—->|)
    

    That will catch all multiline comments and prefixes of monoline ones. Then we need is bring back the monoline prefixes, that we lost:

    Find:
    (.+—->)
    
    Replace:
    <!—-\1
    

    It will fix monoline comments. Combination of “—->“ can not appear xml code otherwise end of comment.

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