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.SummaryLabel + '</b></div>');
myApp.NoneLabel + ')') + '</label></div>';


I would like to leave alone myApp.[variable]

and get rid of, for example. ,

, );

, + '...'


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

3 answers

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.



Replaced string:





Match only the following characters and then replace it with an empty string.

\b[,); +]+.*$







Use this.Replace by


See demo.



I think this works the same:



Replaced string:



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.


All Articles