[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: repeated matches in grep
From: |
Alain Magloire |
Subject: |
Re: repeated matches in grep |
Date: |
Thu, 18 Oct 2001 11:03:48 -0400 (EDT) |
>
> I have seemingly bug-like behaviour from gnu grep version 2.3 and 2.4 for
> linux.
>
> I'm trying to find all the instances of a word that contains 6 of the same
> letter by grepping through /usr/dict/words.
>
> this works:
>
> grep '\(.\).*\1.*\1.*\1.*\1.*\1' /usr/dict/words
>
> but this does not:
>
> grep '\(.\)\(.*\1\)\{5\}' /usr/dict/words
>
> Shouldn't they be equivalent?
>
> In perl, the regular expression (.)(.*\1){5} which seems to be equivalent
> gives the correct results.
>
> I guess this may not be a failure of grep, but rather the regular
> expression library... In any case.
Without too much thought to it, I would say that the engine
is being greedy and matches the longest possible match with
this expression (.*\1) before trying {5}