Notepad++ non-greedy regular expressions

梦想的初衷 提交于 2019-11-30 12:23:15

问题


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.


回答1:


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.




回答2:


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




回答3:


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.




回答4:


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"



来源:https://stackoverflow.com/questions/3971052/notepad-non-greedy-regular-expressions

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