记事本++非贪婪正则表达式

发布于 2024-09-28 11:57:00 字数 174 浏览 1 评论 0原文

Notepad++ 支持非贪婪正则表达式吗?

例如对于文本:

abcxadc

我想使用模式获取部分:

a.+c

现在我得到整个字符串而不是两个部分。我尝试使用“?”操作员但没有成功。

Does Notepad++ support non-greedy regular expressions?

For example for text:

abcxadc

I want to get parts using pattern:

a.+c

And now I get whole string instead of 2 parts. I tried to use the '?' operator but without success.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

完美的未来在梦里 2024-10-05 11:57:00

我使用 Notepad++ V6.1.5 执行了以下操作(它现在具有 PCRE 正则表达式引擎):

a.+?c

并得到 2 部分(abcadc),

现在可以进行惰性(非贪婪)搜索。

I did the following with Notepad++ V6.1.5 (It has now PCRE regex engine):

a.+?c

and got 2 parts (abc and adc)

Lazy(non-greedy) searches are now possible.

妄司 2024-10-05 11:57:00

更新:
从版本 5.9(构建时间 2011 年 3 月 31 日)开始,Notepad++ 支持非贪婪正则表达式(新的 scintilla 2.5)。

Update:
from version 5.9 (build time Mar, 31. 2011), Notepad++ supports non greedy regular expressions (new scintilla 2.5).

生生漫 2024-10-05 11:57:00

注意:此接受的答案自 2011 年 3 月 31 日起已过时。Notepad++ v5.9 及更高版本现在支持非贪婪正则表达式。

此处此处


Notepad++ 不支持惰性 ? 修饰符。相反,您可以指定您不想要的内容:

a[^c]+c

其中指定:匹配 a,后跟一个或多个不是 c< 的字符/code>,后跟 c。这将匹配 abcadc

NOTE: This accepted answer is obsolete as of March 31, 2011. Notepad++ v5.9 and higher now support non-greedy regular expressions.

Please see an updated answer here or here.


Notepad++ doesn't support the lazy ? modifier. Instead, you can specify what you don't want:

a[^c]+c

Which specifies: match a, followed by one or more character that isn't c, followed by c. This will match abc and adc.

木有鱼丸 2024-10-05 11:57:00

在清理可有可无的部分的日志文件时,我在使用带有“全部替换”和空的“替换为”模式的非贪婪正则表达式时遇到了麻烦。
我的解决方案是使模式与整行匹配,而不更改该行的其余部分。

示例:删除第一个分号之前的每个行开头:而不是 ^.+?: -> 现在使用 ^.+?:(.*)$ -> \1 并按“全部替换”

While cleaning up a logfile of dispensable parts, I had trouble using non-greedy regular expression with "Replace All" and an empty "Replace with" pattern.
My solution was to make the pattern match the whole line without changing the rest of the line.

Example: remove every start of line up to the first semicolon: instead of ^.+?: -> now use ^.+?:(.*)$ -> \1 and press "Replace All"

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文