[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: grep -e '\(a\)\1' -e '\(b\)\1'
From: |
Alain Magloire |
Subject: |
Re: grep -e '\(a\)\1' -e '\(b\)\1' |
Date: |
Fri, 16 Feb 2001 11:46:19 -0500 (EST) |
>
> address@hidden (Hans-Bernhard Broeker) writes:
>
> > Tapani Tarvainen <address@hidden> wrote:
> >
> > > The grep command in the subject line doesn't work
> > > correctly with Gnu grep 2.4: it fails to match 'bb'.
> >
> > Looks like pilot error, to me:
> >
> > $ echo bb | grep -e '\(a\)\1' -e '\(b\)\2'
> > bb
>
> That's not the way it should work: multiple -e arguments
> should be treated as independent patterns and back references
> should not refer to previous ones.
Agreed.
> At least that's how I read POSIX.2, and that's the way
> HP-UX grep works.
>
> Same applies when multiple patterns are separated by newline:
>
> grep '\(a\)\1
> \(b\)\1'
>
> should match aa and bb, not ba.
Agreed.
> Incidentally,
>
> echo ba | grep -e '\(a\)\1' -e '\(b\)\1'
>
> doesn't print anything either.
I think we can agreed that current behaviour of GNU grep for BRE
should be fix.
> > > Same problem with egrep '(a)\1|(b)\1'.
> >
> > $ echo bb | egrep '(a)\1|(b)\2'
> > bb
>
> There you are correct, now they are in the same pattern
> (and that's a nonportable Gnu extension anyway).
> But again,
>
> echo ba | egrep '(a)\1|(b)\1'
>
> doesn't print ba either.
If you are sticking with POSIX.2, For ERE the expression is not
portable since, for example on my Solaris box:
$ echo b1a | /usr/xpg4/bin/egrep '(a)\1|(b)\1'
b1a
Thanks for the feedback.
--
au revoir, alain
----
Aussi haut que l'on soit assis, on n'est toujours assis que sur son cul !!!