在记事本++中使用正则表达式在未注释的代码vb.net中查找单词

find word in not commented code vb.net using regex in notepad++

我如何使用搜索词但不在注释文本中搜索,例如我需要查找包含数据表但不以单引号开头的行

property xxx as datatable
proptery xxx as object 'datatable adasdasdas
'dim x as datatable
dim x as datatable = new xxxx

搜索结果应突出显示这些行,因为它们包含单词数据表并且其前面没有单引号 属性 xxx 作为数据表 将 x 调暗为数据表 = new xxxx

谢谢

^([^']*datatable.*?)$

看看DEMO

试试这个:((?<!')datatable)

它在后面使用负向外观,并且应该可以工作,因为记事本使用 PCRE 正则表达式。

See here 为示例。

对于整行,这个呢?

.*((?<!')datatable).*

See here 例如

要找到带有 datatable 的行,它实际上是一条注释,后面没有 = new xxx,请使用以下正则表达式。

正则表达式: (?=.*datatable(?!\s+=\s+new\s+.*))'.*$

解释:

  • (?=.*datatable(?!\s+=\s+new\s+.*)) negative lookaheadpositive lookahead 中的嵌套是为了避免 = new xxx 部分后跟 datatable.

  • '.*$ 匹配注释的其余部分直到行尾。

Regex101 Demo

Notepad++ 演示