Ack with regex - Confusion with simple queries

I am trying to use ack-is-better-than-grep (ack) with regular expressions to search for strings and fragments in my code repository. I understand that ack uses regular expressions of Perl derivatives , is this true?

However, I'm not sure how these queries will work:

ack 'foo' ack '.*(foo)+.*' ack '.*foo' ack 'foo.*' 

Can they give different results? If so, why?

EDIT: In my tests, they give different results (for example, the first prints more matches than the others). They also highlight different parts of the same lines.

EDIT 2: The difference in output seems to be related to the backlight (output coloring). I noticed that if I ran ack with --nocolor , then the output of the commands above is the same. Obviously running ack with the default coloring makes part of the output invisible in my / config machine. I run it on a GNOME terminal from bash on Ubuntu 11.04.

+8
regex ack
source share
1 answer

My understanding is that ack uses regular expressions of a Perl derivative, is this true?

Yes. In fact, ack written in Perl and simply forwards the expressions to the internal engine.

Can they give different results? If so, why?

The expressions should have the same results. However, the output may still be different, since ack allows you to highlight the syntax on its output (by default, if --nocolor is not specified) - it uses ANSI escape codes for color strokes on the output and, obviously, 'foo' highlights something other than '.*foo' (and other requests).

Namely, in the following entry:

 This is a foo test. 

a query for 'foo' will highlight exactly this: " foo ", and '.*foo' will highlight " This is a foo ".

+10
source share