Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Notepad++ non-greedy regular expressions

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.

like image 899
Przemysław Michalski Avatar asked Oct 19 '10 17:10

Przemysław Michalski


People also ask

Can I use regex in Notepad?

Using Regex to find and replace text in Notepad++ In all examples, use select Find and Replace (Ctrl + H) to replace all the matches with the desired string or (no string). And also ensure the 'Regular expression' radio button is set.

What is non-greedy regex?

A non-greedy match means that the regex engine matches as few characters as possible—so that it still can match the pattern in the given string. For example, the regex 'a+?' will match as few 'a' s as possible in your string 'aaaa' . Thus, it matches the first character 'a' and is done with it.

Are Regular Expressions greedy?

The default behavior of regular expressions is to be greedy. That means it tries to extract as much as possible until it conforms to a pattern even when a smaller part would have been syntactically sufficient. Instead of matching till the first occurrence of '>', it extracted the whole string.


2 Answers

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

like image 101
Przemysław Michalski Avatar answered Oct 13 '22 22:10

Przemysław Michalski


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.

like image 23
user1584660 Avatar answered Oct 13 '22 22:10

user1584660