Greg
Greg

Reputation: 34838

How to match c-style block comments in Notepad++ with a regex?

With the intent to match multiline comments, I found the following regex:

  (?:/\*(?:(?:[^*]|\*(?!/))*)\*/)

It is described here. It isn't perfect (it matches comments inside strings), but it works well enough for my purpose. However, it does not work in Notepad++. I tried escaping different things, but with no better results.

Does anyone know how to make this regex work in Notepad++?

Upvotes: 5

Views: 1180

Answers (2)

Jasper
Jasper

Reputation: 11908

When the question was asked, the correct answer was that you couldn't do this in Notepad++, because its regex flavor didn't support regexes matching over multiple lines and lookahead (both of which are essential in the given regex).

However, Notepad++ has a much more powerful regex engine these days - since version 6.0 it supports full pcre regexes. This means your regex as given in the question just works. As such, I believe the correct answer would now just be "open the search menu, input your regex, choose regex for search mode and click search".

Upvotes: 6

PaulF
PaulF

Reputation: 1183

Notepadd++ uses scintilla's regular expression engine (according to its online help).

This page says that "in Scintilla, regular expression searches are made line per line," so unfortunately I think it's hopeless.

-- EDIT --

A little further digging turned up this notepad++ forum post, which offers some hope after all. Specifically, it says that notepad++'s PythonScript plugin supports multiline regular expressions.

Upvotes: 4

Related Questions