删除某个匹配后的所有字符 [英] Remove all characters after a certain match

查看:48
本文介绍了删除某个匹配后的所有字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Notepad++ 从模式末尾删除一些不需要的字符串,这让我终生受益.

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.

我有以下几组字符串:

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

我想只留下 myApp.[variable] 并摆脱,例如,, );, + '...'

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

使用 Notepad++,我可以使用 ^myApp.[a-zA-Z0-9].*?\b 匹配字符串本身(有点乱,但它适用于我需要的).

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.

推荐答案

你不需要去否定.只需将您的正则表达式放在捕获组中并在最后添加一个额外的 .*$ .$ 匹配行尾.所有匹配的字符(整行)都被出现在第一个捕获组中的字符替换.<代码>.匹配任何字符,因此您需要对点进行转义以匹配文字点.

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).*$

替换字符串:

\1

演示

仅匹配以下字符,然后将其替换为空字符串.

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

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

演示

这篇关于删除某个匹配后的所有字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆