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.
我正在使用Notepad ++从模式的末尾删除一些不需要的字符串,这对我来说已经有了我。
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.
我想留下myApp。[变量]并摆脱,例如, ,,),+ +'...'等
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).
使用Notepad ++,我可以使用^ myApp匹配字符串本身。[a-zA-Z0-9]。*?\ b(它有点乱,但它适用于我需要的东西)。
But in reality, I need negate that regex, to match everything at the end, so I can replace it with a blank.
但实际上,我需要否定正则表达式,以匹配最后的所有内容,所以我可以用空白替换它。
3 个解决方案
#1
5
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
OR
Match only the following characters and then replace it with an empty string.
仅匹配以下字符,然后将其替换为空字符串。
\b[,); +]+.*$
#2
2
I think this works equally as well:
我认为这同样有效:
^(myApp.\w+).*$
Replacement string:
\1
From difference between \w and \b regular expression meta characters:
从\ w和\ b正则表达式元字符之间的差异:
-
\w
stands for "word character", usually[A-Za-z0-9_]
. Notice the inclusion of the underscore and digits.
\ w代表“单词字符”,通常是[A-Za-z0-9_]。请注意包含下划线和数字。
#1
5
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
OR
Match only the following characters and then replace it with an empty string.
仅匹配以下字符,然后将其替换为空字符串。
\b[,); +]+.*$
#2
2
I think this works equally as well:
我认为这同样有效:
^(myApp.\w+).*$
Replacement string:
\1
From difference between \w and \b regular expression meta characters:
从\ w和\ b正则表达式元字符之间的差异:
-
\w
stands for "word character", usually[A-Za-z0-9_]
. Notice the inclusion of the underscore and digits.
\ w代表“单词字符”,通常是[A-Za-z0-9_]。请注意包含下划线和数字。