Closed elias6 closed 7 years ago
Though, if I run echo 'xy' | ack '(?<=(?:x))y'
, then it prints xy
with the y highlighted. The regular expression capturing x
must confuse ack 2.08 somehow (I'm on OS X 10.6.8, but I was able to reproduce the problem, so I don't think OS version is part of the problem).
Just for giggles, I tried it with a copy of ack 1.94 I had lying around, and echo 'xy' | ack '(?<=x)y'
, echo 'xy' | ack '(?<=(x))y'
and echo 'xy' | ack '(?<=(?:x))y'
all printed xy
with the y highlighted.
@mikez302 Thanks for the bug report! I'll take a more in-depth look later today.
Yes, Andy has said elsewhere that he considers highlighting $1
from capturing parens instead of always highlighting $&
to be a known bug in ack2, which will be fixed in ack3 .
This also means ack2 'x(y)'
will highlight the same as ack2 '(?<=x)y'
( but it won't in ack3 ).
The workaround for now is as @packy notes to use non-capturing parens (?:...)
if you need parens but don't want to focus the highlight there.
This is fixed in ack 3. I'm leaving the feature in ack 2 as-is.
I am running ack 2.08 on OS X 10.8.4. If I run
echo 'xy' | ack '(?<=x)y'
from the terminal, it printsxy
with the y highlighted, like I would expect. But if I runecho 'xy' | ack '(?<=(x))y'
, then it printsxy
with the x highlighted. Is this intended behavior or a bug? I would think the y is the actual match and the x is not part of it. The grouping should have nothing to do with it.