确认搜索文字字符串

tes*_*ter 16 grep regex

当我想搜索 html 标签的一部分时,我厌倦了不得不逃避的事情。

我怎样才能准确搜索我输入的内容不必转义?

例如

ack-grep 'console.log(foo'
Run Code Online (Sandbox Code Playgroud)

我得到:

Unmatched ( in regex; marked by <-- HERE in m/console.log( <-- HERE par/
Run Code Online (Sandbox Code Playgroud)

And*_*ter 21

你必须逃避正则表达式。

ack 'console\.log\(foo'
Run Code Online (Sandbox Code Playgroud)

(你应该转义,.这样你就不会匹配“consoleflog”,因为.匹配任何单个字符)

如果您不想这样做,请这样做以自动引用每个元字符。

ack -Q 'console.log(foo'
Run Code Online (Sandbox Code Playgroud)

  • \Q 在我的服务器上不起作用。`ack '\Qconsole.log(foo' ack: Invalid regex '\Qconsole.log(foo': Unmatched ( in regex; by &lt;-- HERE in m/\Qconsole.log( &lt;-- HERE foo/` (2认同)