My goal is the regex to match everything but the multi-line matches from the original regex.
我的目标是使regex匹配除来自原始regex的多行匹配之外的所有内容。
This is the regex which I'm trying to invert:
这是regex,我想把它颠倒过来
\vselect\_.{-};
\ vselect \ _。{ - };
It matches correctly on the bellow sample code.
The sql statements are included and not the capitalized text.
它与下面的示例代码匹配正确。包含sql语句,而不是大写文本。
THIS TEXT IS WHAT I WANT TO
MATCH ONCE THE ABOVE
REGEX IS CORRECTLY INVERTED.
select *
from foo
where bar;
THIS TEXT IS WHAT I WANT TO
MATCH ONCE THE ABOVE
REGEX IS CORRECTLY INVERTED.
select *
from bar
where foo;
THIS TEXT IS WHAT I WANT TO
MATCH ONCE THE ABOVE
REGEX IS CORRECTLY INVERTED.
Following the vim documentation on how to do invert (negate) a regex, this is what I come up with:
按照vim文档中关于如何对regex进行反转(否定)的说明,这就是我的想法:
\v^(select\_.{-};)@!.*
\ v ^(选择\ _ { - };)@ !。*
This regex matches on everything but on the first lines from the sql statements. I want all lines from the sql statements to be excluded and not just the first lines.
这个regex将匹配除sql语句的第一行之外的所有内容。我希望排除sql语句中的所有行,而不仅仅是第一行。
I also tried not to use the \v
very magic directive and escaped everything, but no luck, getting the same result.
我也试着不使用\v非常神奇的指令去逃避一切,但是没有运气,得到同样的结果。
What am I doing wrong?
Also if anyone can think of another way to accomplish what I'm trying to do would be great, the answer does not have to follow the way I'm trying it.
我做错了什么?另外,如果有人能想出另一种方法来完成我正在尝试的事情,那就太棒了。
1 个解决方案
#1
2
After thinking it over, I think I got what you meant...
仔细考虑之后,我想我明白你的意思了……
This line should work for you:
这条线应该适合你:
\v;\n\n\zs\_.{-}\ze\n\_^select
Update according to the comment:
And this vimregex works if you have leading/ending TEXT blocks:
这个vimregex可以工作,如果你有引导/结束文本块:
\v(;\n\n\zs\_.{-}|%^(select)@!\_.{-})\ze(\n\_^select|\n?%$)
#1
2
After thinking it over, I think I got what you meant...
仔细考虑之后,我想我明白你的意思了……
This line should work for you:
这条线应该适合你:
\v;\n\n\zs\_.{-}\ze\n\_^select
Update according to the comment:
And this vimregex works if you have leading/ending TEXT blocks:
这个vimregex可以工作,如果你有引导/结束文本块:
\v(;\n\n\zs\_.{-}|%^(select)@!\_.{-})\ze(\n\_^select|\n?%$)