[英]What is the correct VIM regexp to search to get = but not ==?
In the following code: 在以下代码中:
a = b = c == 1
I'd like to match on only the first two =, but not the == at the end. 我想只匹配前两个=,而不是最后的==。
I figured the pattern \\<=\\>
would work since \\<
matches beginning of word and \\>
matches the end. 我认为模式
\\<=\\>
将起作用,因为\\<
匹配单词的开头, \\>
匹配结束。 But it doesn't. 但事实并非如此。 What's wrong with this pattern and what is the correct pattern?
这种模式有什么问题,正确的模式是什么?
vim supports lookarounds, so you can use a negative lookbehind and negative lookahead surrounding the =. vim支持lookarounds,所以你可以使用负面的lookbehind和负面的前瞻来围绕=。 This will match only the desired = and even = at the start or end of the line.
这将仅匹配行的开头或结尾处的期望=和偶数=。
\(=\)\@<!=\(=\)\@!
You cannot use \\<=\\>
because usually, the equals character is not a keyword character . 您不能使用
\\<=\\>
因为通常,equals字符不是 关键字字符 。 You could fix that with :set iskeyword+==
, but that may have side effects for navigating and syntax highlighting. 您可以使用以下方法解决此问题
:set iskeyword+==
,但这可能会导致导航和语法突出显示的副作用。
This regex should work: 这个正则表达式应该工作:
[^=]=[^=]
It will break if you want to match single =
at the beginning or at the end of line - but I figured this is not an issue for your patterns. 如果你想在行的开头或末尾匹配single
=
会破坏 - 但我认为这不是你的模式的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.