Paul Jarc schrieb:
Bernd Eggink <[EMAIL PROTECTED]> 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.

Thanks, that made it clear. The crucial point, that the longest match is preferred in any case, had slipped out of my mind (though I have been using this for decades...).

Regards,
Bernd

--
Bernd Eggink
[EMAIL PROTECTED]
http://sudrala.de


Reply via email to