bug-bash
[Top][All Lists]
Advanced

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

Re: capturing sub-expressions?


From: Paul Jarc
Subject: Re: capturing sub-expressions?
Date: Tue, 29 Jan 2008 16:29:56 -0500
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.1 (gnu/linux)

Bernd Eggink <address@hidden> wrote:
> My impression is that the pattern lookup depends on whether or not a
> !' is involved. If the pattern does not contain a '!', the shell looks
> for matching substrings, from left to right. If it contains a '!', the
> value as a whole is matched.

It looks for substrings in both cases - specifically, the longest
matching substring, which might happen to be the entire string.  With
!(), that is often the case.

>     x=12ab34; echo ${x//+([0-9])/X}        # prints XabX
>     x=12ab34; echo ${x//!(+([0-9]))/X}     # prints X
>
> If the same algorithm had been applied in the 2nd case, the first
> substring matching the pattern "not a sequence of at least one digit"
> would have been 'a' (or maybe 'ab'), and the output would have been
> 12Xb34' (or '12X34').

"12ab34" is also "not a sequence of at least one digit", so as the
longest match, it is preferred.

Note how "not a sequence of at least one digit" differs from "a
sequence of at least one nondigit"; the latter is specified as
+([!0-9]) and has the behavior you expect !(+([0-9])) to have.

> IMHO (please correct me if I'm wrong) this contradicts the usual
> meaning of the '!' operator

Negation is negation, but it has different effects on the overall
result depending on where you place it in the pattern.


paul




reply via email to

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