如何将Notepad ++中的c风格块注释与正则表达式相匹配?

时间:2022-10-01 22:29:10

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.

这里描述。它并不完美(它匹配字符串中的注释),但它足以满足我的目的。但是,它在Notepad ++中不起作用。我试图逃避不同的事情,但没有更好的结果。

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

有谁知道如何使这个正则表达式在Notepad ++中工作?

2 个解决方案

#1


3  

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

Notepadd ++使用scintilla的正则表达式引擎(根据其在线帮助)。

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

这个页面说“在Scintilla中,正则表达式搜索每行都行,”不幸的是,我认为这是没有希望的。

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

进一步挖掘了这个记事本++论坛帖子,毕竟提供了一些希望。具体来说,它说notepad ++的PythonScript插件支持多行正则表达式。

#2


5  

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

当问到这个问题时,正确的答案是你不能在Notepad ++中这样做,因为它的正则表达式味道不支持匹配多行和前瞻的正则表达式(这两者在给定的正则表达式中都是必不可少的)。

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

但是,Notepad ++最近有一个更强大的正则表达式引擎 - 从版本6.0开始它支持完整的pcre正则表达式。这意味着问题中给出的正则表达式正常。因此,我相信正确的答案现在只是“打开搜索菜单,输入正则表达式,选择正则表达式进行搜索模式并单击搜索”。

#1


3  

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

Notepadd ++使用scintilla的正则表达式引擎(根据其在线帮助)。

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

这个页面说“在Scintilla中,正则表达式搜索每行都行,”不幸的是,我认为这是没有希望的。

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

进一步挖掘了这个记事本++论坛帖子,毕竟提供了一些希望。具体来说,它说notepad ++的PythonScript插件支持多行正则表达式。

#2


5  

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

当问到这个问题时,正确的答案是你不能在Notepad ++中这样做,因为它的正则表达式味道不支持匹配多行和前瞻的正则表达式(这两者在给定的正则表达式中都是必不可少的)。

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

但是,Notepad ++最近有一个更强大的正则表达式引擎 - 从版本6.0开始它支持完整的pcre正则表达式。这意味着问题中给出的正则表达式正常。因此,我相信正确的答案现在只是“打开搜索菜单,输入正则表达式,选择正则表达式进行搜索模式并单击搜索”。