Search code examples
ack

ack: how to match beginning of words?


I'm using ack like this: ack-grep assets\\. (on Ubuntu)

However, I want to exclude results which do not begin with "assets". For example: siteassets.

So far I've tried ack-grep ^assets\\. and other random stuff.

(in Vim regex, the pattern is like this: \<assets\. e.g. :help \<)


Solution

  • ack command has an option -w to force PATTERN match whole word.00

    -w, --word-regexp Force PATTERN to match only whole words

    So, you can use

    ack -w assets\.
    

    According to doc