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

只愿长相守 提交于 2020-01-03 13:33:47

问题


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++?


回答1:


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.




回答2:


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".



来源:https://stackoverflow.com/questions/5112757/how-to-match-c-style-block-comments-in-notepad-with-a-regex

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!