Search code examples
regexnotepad++regex-greedy

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.


Solution

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