I have a piece of software that, given a regex, can perform a find and replace. It's not a coding language, so no suggestions other than regex will be useful. I have searched looking for an expression that will help me find all text except "pattern". The pattern is not necessarily at the start or the end of the string, and can occur multiple times. Given the string:
我有一个软件,给定一个regex,它可以执行查找和替换。它不是一种编码语言,所以除了regex之外没有任何建议是有用的。我搜索了一个表达式,可以帮助我找到除“pattern”之外的所有文本。模式不一定在字符串的开头或结尾,并且可以多次出现。给定的字符串:
red blue yellow green orange purple blue black green white
and a pattern:
和一个模式:
blue.*?green
a pattern that appears twice on the line, I am trying to select everything but. (with a view to removing the selected and leaving just the pattern). I have tried:
在这条线上出现了两次的模式,我尝试着选择所有的东西。(视图删除选中的,只保留模式)。我有尝试:
FIND - ".*?(blue.?green)"
REPLACE - "$1",
but that still leaves "white" on the end. Any help would be appreciated.
但最后还是留下了“白色”。如有任何帮助,我们将不胜感激。
1 个解决方案
#1
2
It's usually something like this
通常是这样的
Find (?:(?!blue.*?green).)*(blue.*?green)?
Replace $1
找到(?:? !蓝色。* ?绿色))*(蓝色。* ?绿色)?取代1美元
Expanded
扩大
(?:
(?! blue .*? green )
.
)*
( blue .*? green )? # (1)
Output
输出
blue yellow greenblue black green
#1
2
It's usually something like this
通常是这样的
Find (?:(?!blue.*?green).)*(blue.*?green)?
Replace $1
找到(?:? !蓝色。* ?绿色))*(蓝色。* ?绿色)?取代1美元
Expanded
扩大
(?:
(?! blue .*? green )
.
)*
( blue .*? green )? # (1)
Output
输出
blue yellow greenblue black green