22

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.

<!--- MPU ---> 

should be left untouched, while

<!--
************
blablabla
************
-->

should be removed.

I know the Notepad++ feature to lookup through more than a document with regexp and I'm tryin to use it but I have some difficulty. For a start I'm trying this regexp:

<\!\-\-(.*?)\-\->

which tested in here: http://www.regextester.com/ works at least partially (because it highlights the comments made of just on line) But if I copy and paste this regexp on Notepad++ it will match just the one-line comments =\

Does anybody know how to do this in Notepad++?

Alan Moore
  • 73,866
  • 12
  • 100
  • 156
Andrea Silvestri
  • 1,082
  • 4
  • 14
  • 41

5 Answers5

46

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

fresskoma
  • 25,481
  • 10
  • 85
  • 128
lilwupster
  • 873
  • 9
  • 11
  • Wow, writing `<\!\-\-(.*?)\-\->` and selecting that one really seems to work! Thank you. Now I just have to find out how to exclude the mono-line ones – Andrea Silvestri Dec 18 '12 at 14:47
4

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

Mike Perrenoud
  • 66,820
  • 29
  • 157
  • 232
1

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 what 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

<!--[*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]*-->

anthonyme
  • 23
  • 4
0

A simple trick if it was a single document, is to convert the line endings to Unix .

Menu: [Edit] -> [EOL Conversion] -> [Unix]

Then just use simple \n to detect newline in your expression.

This way you don't have to change expressions constructed/copied from some online regex builders.

note: don't forget to switch line endings back to Windows, just in case.

Assem
  • 516
  • 3
  • 10
  • How is this answering the question? – Toto Feb 09 '22 at 12:31
  • I know the question is about "multiple" documents at once, where my hint won't help this specific case. But I though it could help others who land on this question because they need to find how to handle multi-line search in the NP++ without the need to change a per-constructed search expression that depends on \n for new lines or setting the '.' to be include newlines in search dialog. – Assem Feb 09 '22 at 20:01