8

I am using Notepad++ to remove some unwanted strings from the end of a pattern and this for the life of me has got me.

I have the following sets of strings:

myApp.ComboPlaceHolderLabel,
myApp.GridTitleLabel);
myApp.SummaryLabel + '</b></div>');
myApp.NoneLabel + ')') + '</label></div>';

I would like to leave just myApp.[variable] and get rid of, e.g. ,, );, + '...', etc.

Using Notepad++, I can match the strings themselves using ^myApp.[a-zA-Z0-9].*?\b (it's a bit messy, but it works for what I need).

But in reality, I need negate that regex, to match everything at the end, so I can replace it with a blank.

keldar
  • 6,152
  • 10
  • 52
  • 82

3 Answers3

10

You don't need to go for negation. Just put your regex within capturing groups and add an extra .*$ at the last. $ matches the end of a line. All the matched characters(whole line) are replaced by the characters which are present inside the first captured group. . matches any character, so you need to escape the dot to match a literal dot.

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

Replacement string:

\1

DEMO

OR

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

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

DEMO

Avinash Raj
  • 172,303
  • 28
  • 230
  • 274
3

I think this works equally as well:

^(myApp.\w+).*$

Replacement string:

\1



From difference between \w and \b regular expression meta characters:

  • \w stands for "word character", usually [A-Za-z0-9_]. Notice the inclusion of the underscore and digits.
Community
  • 1
  • 1
csiu
  • 3,159
  • 2
  • 24
  • 26
2
(^.*?\.[a-zA-Z]+)(.*)$

Use this.Replace by

$1

See demo.

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

vks
  • 67,027
  • 10
  • 91
  • 124