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.

+3


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.

^(myApp\.[a-zA-Z0-9].*?\b).*$

      

Replaced string:

\1

      

DEMO



OR

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

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

      

DEMO

+4


source


(^.*?\.[a-zA-Z]+)(.*)$

      

Use this.Replace by

$1



See demo.

http://regex101.com/r/lU7jH1/5

+2


source


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.
+2


source







All Articles