bug-gnu-utils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Grep and --color


From: Stepan Kasal
Subject: Re: Grep and --color
Date: Tue, 3 Jun 2003 10:18:39 +0200
User-agent: Mutt/1.2.5.1i

Hello,
        again, thank you very much for your bug report.

On Tue, Jun 03, 2003 at 09:29:14AM +0300, Jori Mantysalo wrote:
> If I say
>  echo "aaaab" | grep -E --color=auto "((aaa)|(aa))*"
> I get four red-colored a-letter, but with command
>  echo "baaaab" | grep -E --color=auto "((aaa)|(aa))*"
> I just get gray text.
> So, grep finds match, but doesn't always color it.

(Similarily,
        echo "baaaab" | grep -E -o "((aaa)|(aa))*"
doesn't find the match.)

I'd guess this is a bug in regex engine.
(dfa.c finds the line but regex.c is not able to find the match.)

The bug will be fixed when grep upgrades to the new regex engine,
distributed with glibc.

> What are the rules when matching with --only-match ? When I said
>   echo "aaaa" | grep -E --color=auto "((aaa)|(aa))"
> I got four red-colored letter,

In my case only three a's are red, which is correct.
Try rebuilding grep-2.5.2 with ./configure --with-included-regex
to see whether this particular bug will disappear.

> but then when I said
>  echo "aaaa" | grep -E --color=auto -o "((aaa)|(aa))"
> I got three red-colored letter and not two lines with two a's in both.

Again, this is correct.

> So, is grep greedy or not when matching?

When you match the string against the regex, the process is greedy---
you get the longest possible match.
Only when this first match is done, you proceed and try to find another
match after the first one.

Have a nice day,
        Stepan Kasal




reply via email to

[Prev in Thread] Current Thread [Next in Thread]