Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am sick of having to escape things when I want to search for part of an html tag.

How can I ack search for exactly what I type without having to escape stuff?


ack-grep 'console.log(foo'

I get:

Unmatched ( in regex; marked by <-- HERE in m/console.log( <-- HERE par/
share|improve this question

closed as off topic by Zoredache, Rilindo, voretaq7 Oct 25 '12 at 19:37

Questions on Server Fault are expected to relate to server, networking, or related infrastructure administration within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

Use a different shell? Put it in quotes? Place your search string in a file, I suspect ack-grep can get the string from a file. Perhaps you can even could even get the search via stdin. – Zoredache Mar 1 '12 at 22:08
@Zoredache I added a better example.. I don't want to have to escape (.. and what do you mean by better shell? – tester Mar 1 '12 at 22:10
I mean all the chracters you are complaining about are handled by your shell (bash/zsh/whatever). The problem has nothing to do with the tool. The problem is that the shell is not sending what you type. – Zoredache Mar 1 '12 at 22:12
Ah I think i found it.. -Q uses it literally.. – tester Mar 1 '12 at 22:14
up vote 6 down vote accepted

You have to escape the regex.

ack 'console\.log\(foo'

(You should escape the . so that you don't match "consoleflog", because . matches any single character)

You can use Perl's `\Q' metacharacter to quote the entire string:

ack '\Qconsole.log(foo'

And if you would rather not do that, do this:

ack -Q 'console.log(foo'

The -Q takes its letter from its parallel to \Q

share|improve this answer
\Q does not work on my server. ack '\Qconsole.log(foo' ack: Invalid regex '\Qconsole.log(foo': Unmatched ( in regex; marked by <-- HERE in m/\Qconsole.log( <-- HERE foo/ – Sebastien Dec 1 '14 at 12:37

Not the answer you're looking for? Browse other questions tagged or ask your own question.