Remove all characters after a specific match
I am using Notepad ++ to remove some unwanted lines from the end of the template, and this has been my life for me.
I have the following line groups:
myApp.ComboPlaceHolderLabel,
myApp.GridTitleLabel);
myApp.SummaryLabel + '</b></div>');
myApp.NoneLabel + ')') + '</label></div>';
I would like to leave alone myApp.[variable]
and get rid of, for example. ,
, );
, + '...'
Etc.
Using Notepad ++ I can line up the lines with ^myApp.[a-zA-Z0-9].*?\b
(it's a bit messy, but it works for what I need).
But I actually need to negate this regex to match everything at the end, so I can replace it with empty.
source to share
You don't have to go for denial. Just put your regex in capturing groups and add an extra .*$
one one last time. $
matches the end of the line. All matching characters (the whole string) are replaced by characters that are present within the first captured group. .
matches any character, so you need to escape the dot to match the literal dot.
^(myApp\.[a-zA-Z0-9].*?\b).*$
Replaced string:
\1
OR
Match only the following characters and then replace it with an empty string.
\b[,); +]+.*$
source to share
I think this works the same:
^(myApp.\w+).*$
Replaced string:
\1
From the difference between \ w and \ b regex metacharacters :
-
\w
denotes a word symbol, usually[A-Za-z0-9_]
. Note the inclusion of underscores and numbers.
source to share