在grep / ack中转义括号 [英] Escaping a parenthesis in grep/ack

查看:314
本文介绍了在grep / ack中转义括号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想查找字符串methodname(,但我无法转义(。我怎么能得到

  grep methodname(* 



  ack-grep methodname(* 

解决方案有两件事解释:shell和 ack-grep



您可以使用'' \ shell,例如

  grep'methodname('* 
grepmethodname(*
grep methodname \(*

grep 正则表达式语言默认情况下是这样的,所以不是特殊的。(如果你使用 egrep grep -E grep -P 。)



另一方面, ack-grep 以Perl正则表达式作为输入,其中也是特殊的,因此您也必须将其转义。

  ack-grep'methodname \('* 
ack-grepmethodname \\(*
ack-grep methodname \\\(*
ack-grep'methodname [(]'*
ack-grepmethodname [(]*
ack-grep methodname \ [\(\] *


I want to look for the string "methodname(", but I am unable to escape the "(". How can I get

grep methodname( *

or

ack-grep methodname( *

to work?

解决方案

There's two things interpreting the (: the shell, and ack-grep.

You can use '', "", or \ to escape the ( from the shell, e.g.

grep 'methodname(' *
grep "methodname(" *
grep methodname\( *

grep uses a basic regular expression language by default, so ( isn't special. (It would be if you used egrep or grep -E or grep -P.)

On the other hand, ack-grep takes Perl regular expressions as input, in which ( is also special, so you'll have to escape that too.

ack-grep 'methodname\(' *
ack-grep "methodname\\(" *
ack-grep methodname\\\( *
ack-grep 'methodname[(]' *
ack-grep "methodname[(]" *
ack-grep methodname\[\(\] *

这篇关于在grep / ack中转义括号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆