← Back to Upcase

Getting better at Ag

(Geoff Harcourt) #1

@joshclayton, I really liked your post about tab completion with ag.

Question for Josh or anyone else who knows ag and ack: I am pretty awful at Ag. I find that whenever I try to do anything beyond the simplest searches (include some weird characters or use regex), I get some kind of syntax error. My fallback when I’m in a hurry is just to do a simpler search and then visually parse the longer results of the query, which is clearly suboptimal.

My googling hasn’t really yielded a great resource for how to better construct ag searches, which either means I’m bad at all kinds of search (web and ack/ag!), or that I’m just looking in the wrong place. Is there a good tutorial that you send people to when they are trying to move beyond the basics? Is it just a matter of knowing Perl-style regex?

(Joshua Clayton) #2

@geoffharcourt regarding regexps, I try to stick to the basics (largely for the same reasons you mentioned), regexes with simple wildcards, like ag 'user.*email', ag '\d{3,}', or ag '</li>$'.

I think the thing that most commonly bites me is forgetting to escape periods or question marks - and if you can identify the ones that trip you up most, it’s easier to work on fixing it (by building that muscle memory).

(Geoff Harcourt) #3

@Joshua_Clayton, thanks for the tip.