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

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

Re: is expr's \? regex metachar working?


From: Paul Jarc
Subject: Re: is expr's \? regex metachar working?
Date: Thu, 23 Aug 2001 17:23:20 -0400
User-agent: Gnus/5.090004 (Oort Gnus v0.04) Emacs/20.7

Clark Morgan <address@hidden> wrote:
> On Thu, Aug 23, 2001 at 04:47:31PM +0200, Andreas Schwab wrote:
>> ????  The regexp _is_ matching, since expr prints > 0.
> 
> $ ./expr "abcdef" : '.*b'
> 2
> $ ./expr "abcdef" : '.*b\+'
> 2
> $ ./expr "abcdef" : '.*b\?'
> 6
> 
>    Does this illustrate why I think it's broken?
> 
>    Remember, the docu says:  0 or 1 matches.  It seems to me that \?
>    matches 0 occurrences always.

The problem here is not with '\?', but with '.*'.  It's greedy - it
matches as much as possible.  You want something that matches as
little as possible.  In this case, you can use '[^b]*b\?'.  That will
still match all strings, but it'll match only the empty leading string
when there is no 'b', and it'll match only up to the 'b' when there is
one.


paul



reply via email to

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