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

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

Re: sed version 3.02


From: Uwe F Mayer
Subject: Re: sed version 3.02
Date: Wed, 4 Sep 2002 14:29:07 -0400 (EDT)

Actually, the explanation with the greedy match is inconsistent with the
observed behavior. If greedy mathing did in fact occur, then of course
/^0*\([0-9]\)/ will not match 00, just as observed, but neither would
/^0*\(0\)/ match the string 00, however, it does. Hence greedy matching
is not a good explanation.

In fact, /0*0/, /[0-0]*0/ and /[0-0]*[0-0]/ all match 00, but /0*[0-0]/
does not.

I certainly do agree that this is a problem with the regular expression
handling, and it ought to be fixed in the routines that ship with sed.

Uwe
-----------------------------------------------------------------------
On Wed, 4 Sep 2002, Uwe Steinfeld wrote:

> Hello Uwe,
>
> Tuesday, September 3, 2002, 6:23:12 PM, you wrote:
>
> UFM> The command
> UFM> echo '00' | sed -e 's/^0*\([0-9]\)/\1/'
> UFM> returns
> UFM> 00
> UFM> while it should return
> UFM> 0
> UFM> I am saying it should return 0 because that's what's returned by the
> UFM> SunOS version of sed, and also what isreturned by the equivalent perl
> UFM> command. Note that
> UFM> echo '00' | sed -e 's/^0*\(0\)/\1/'
> UFM> does in fact return
> UFM> 0
>
> I think the reason is that the regex version included in sed 3.02 does
> a "greedy matching" to speak in terms of Perl. It eats all the 0's for
> "0*" and then nothing is left to match [0-9]. So the match fails and
> the input string is returned unchanged. Cygwin and Linux (SuSE 7.3)
> give me the same result.
>
> Solution: rebuild sed with a newer regex library. I used the version
> the comes with the new GNU coreutils package and it works fine.
>
>

-- 
-----------------------------------------------------------------------
Uwe F. Mayer <address@hidden> www.math.vanderbilt.edu/~mayer
Uwe F. Mayer <address@hidden> www.tux.org/~mayer
PGP key available via finger and via the world wide web page
-----------------------------------------------------------------------





reply via email to

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