Replace (Select) All except a string with Regex and Notepad++

This worked for me. I could not really find the full expression anywhere so here it is. It works with Notepad++ 6.1.5 . I know for a fact that it does not work with some other regular expression implementations.

Let’s say you have a bunch of text and you want Notepad++ to replace (select) all of the text except the string blahblah.
Open the Replace tool (Ctrl+H).
In the “Find what” field enter this:

(?<=blahblah)(.+)|(.+)(?=blahblah)|^((?!blahblah).)*$

Do not enter anything in the "Replace with" field if you want to remove everything except blahblah
Make sure that you also select the "Regular expression" radio button at the bottom of the Replace window.
Click on "Replace All" ...
Voila, you should have only the blahblah text left.

If you would like to remove everything except 5 digit numbers, you could do this:

(?<=[0-9]{5})(.+)|(.+)(?=[0-9]{5})|^((?![0-9]{5}).)*$

There is an explanation for this:

(?<=blahblah)(.+)

removes all characters after string blahblah to the end of the line (in lines that contain the blahblah string).

(.+)(?=blahblah)

removes all characters before string blahblah from the beginning of the line (in lines that contain the blahblah string).

^((?!blahblah).)*$

marks all lines that do not contain string blahblah

These are piped together with "|".

Is this the best way to do this? Most likely not, but it does get the job done and I did not see it documented elsewhere.

This post on stackoverflow.com definitely helped.