regex - How to match start and end of a string? -
i'm trying use notepad++'s find & replace regular expression on following sample:
3 733xxxx (-1) 3 1521xxxx (-1) 3 1521xxxx (-1)
how can keep following unmatched?
733xxxx 1521xxxx 1521xxxx
i've tried using following expressions:
^(.* \(-1\)).*$ ^(\(-1\))$
the first 1 matches everything, second: nothing.
can point me in right direction?
there several ways approach this:
replace
"^ *\d+ +"
," *\(-1\)$"
(the quotes clarity) empty string (2 steps)replace
"^ *\d+ +(\d+).*$"
$1
\d
short-hand character class, matches whatever [[:digit:]]
matches (numeric digits). (notepad++ uses boost regex). testing, seems it can match unicode numeric digits, don't think going matter in application.
the ^ *\d+ +
part match text before numbers in middle.
*\(-1\)$
matches spaces , (-1)
@ end of line.
for ^ *\d+ +(\d+).*$
, regex match whole line, retain part want, numbers in middle. ()
(which not escaped in *\(-1\)$
) capturing group, captures text sub-pattern matches. don't care text following captured number, use .*
match everything.
Comments
Post a Comment