bug-bash
[Top][All Lists]
Advanced

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

Re: capturing sub-expressions?


From: Bernd Eggink
Subject: Re: capturing sub-expressions?
Date: Tue, 29 Jan 2008 23:57:04 +0100
User-agent: Thunderbird 2.0.0.9 (X11/20071031)

Paul Jarc schrieb:
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.

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
address@hidden
http://sudrala.de




reply via email to

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