如何只查找未注释的模式?

时间:2013-06-06 11:58:48

标签: regex vim

我有一些代码,其中相同的条件ABC用作if子句的一部分,在它的末尾(作为注释)和过时的部分(我不想删除)。一个例子可能如下所示:

if (ABC) //this is the only line that should be matched, this comment should not change the outcome of the search
 {
   lots of code
 } // if (ABC)


//if (ABC)
// {
//   lots of obsolete code
// } // if (ABC)

我如何告诉vim只搜索模式ABC,而不是通过//在同一行之前发生的注释?

^.*\(\/\/\)\@!.*ABC不起作用,因为.*和[{1}}抱怨“嵌套*”也符合//

有什么想法吗?

谢谢

1 个答案:

答案 0 :(得分:4)

对于您问题中的示例,此行有效:

/\v(\/\/.*)@<!ABC

或没有very magic

/\(\/\/.*\)\@<!ABC