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: Clark Morgan
Subject: Re: is expr's \? regex metachar working?
Date: Thu, 23 Aug 2001 08:11:54 -0700
User-agent: Mutt/1.2.5i

On Thu, Aug 23, 2001 at 05:05:46PM +0200, Andreas Schwab wrote:
> Clark Morgan <cmorganOaracnet.com> writes:
> 
> |> 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?
> 
> No, not at all.
> 
> |>    Remember, the docu says:  0 or 1 matches.  It seems to me that \?
> |>    matches 0 occurrences always.
> 
> Be carefull with such a statement, you have to check *all* cases, but a
> single couterexample is enough to prove the opposite:
> 
> $ expr "abcdef" : 'a\?bcd'
> 4
> 
> You can only look at a regexp as a whole, context matters. 

But, and this is a big BUT, expr puts an implied '^' at the beginning of
every regexp.  Consequently, when matching a nontrivial pattern, you've got
no choice but to add .* at the beginning of the regexp if you want to find
a substring.



reply via email to

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