如何从ack结果中排除注释?

Shy*_*lux 9 configuration comments ack

嗨即时通讯ack(实际上半小时前开始).我对搜索结果的质量印象深刻.

但是在我的源文件中有很多注释,如果我搜索一个类/函数名,我会得到大约20个带有注释行的结果和带有实际代码的2个结果.

有没有办法在之后//和#之间排除文本/* */?

sin*_*ina 4

你可以用这样的东西跳过单行注释;

# ignore matches after //
ack '^[^//]*word'
# ignore matches after #
ack '^[^#]*word'
Run Code Online (Sandbox Code Playgroud)

如果您使用ag的是,请记住它会进行多行匹配:

# ignore matches after //
ag '^[^\n\r//]*word'
# ignore matches after #
ag '^[^\n\r#]*word'
Run Code Online (Sandbox Code Playgroud)