Reputation: 20806
I'm trying to use Notepad++'s find & replace with a regular expression on the following sample:
3 733xxxx (-1)
3 1521xxxx (-1)
3 1521xxxx (-1)
How can I keep only the following unmatched?
733xxxx
1521xxxx
1521xxxx
I've tried using the following expressions:
^(.* \(-1\)).*$
^(\(-1\))$
The first one matches everything, the second: nothing.
Can anyone point me in the right direction?
Upvotes: 0
Views: 78
Reputation: 56819
There are several ways to approach this:
Replace "^ *\d+ +"
and " *\(-1\)$"
(the quotes are for clarity) with empty string (2 steps)
Replace "^ *\d+ +(\d+).*$"
with $1
\d
is a short-hand character class, which matches whatever [[:digit:]]
matches (numeric digits). (Notepad++ uses Boost regex). From my testing, it seems that it can match Unicode numeric digits, but I don't think it is going to matter much in your application.
The ^ *\d+ +
part will match the text before the numbers in the middle.
*\(-1\)$
matches spaces and the (-1)
at the end of the line.
For ^ *\d+ +(\d+).*$
, the regex will match the whole line, then we will retain only the part that we want, which is the numbers in the middle. The ()
(which are not escaped like in *\(-1\)$
) is a capturing group, which captures the text the sub-pattern matches. We don't care about the text following the captured number, so we use .*
just to match everything.
Upvotes: 2