Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Example of use of (S) flag
- X-seq: zsh-users 21105
- From: Mikael Magnusson <mikachu@xxxxxxxxx>
- To: Philippe Troin <phil@xxxxxxxx>
- Subject: Re: Example of use of (S) flag
- Date: Mon, 28 Dec 2015 20:13:05 +0100
- Cc: Zsh Users <zsh-users@xxxxxxx>
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=EZmDxurN6eE9/3j4Ga1mK3Bs6Bc+vbFM3MrNGeUfUEg=; b=CL5OCoUWhSAmkND84JCqO4ggt6KQ3ljXpYoBJbnSKVLpuRqMzUAm2yGnfsJ7vhnxgY Xy03UyFWVljjhGmjMt9absh9EICizddxmMsBER4oJAIjtjbw453cKAwtBVr7wjJbSBec kkC6wxv6Us6waD3cTal5Y97ZI9CLv/Cfc4mndjVKGpVC4UGQzGprofMe49G+DdH3H4Uh OEffwgn9kSSU4qjNMW3PDEeKqDrjAPtZ82TaO384bLDTzTws/SlDZzB4pPBQ/6Ydcygs 5TsBLG6tpe26hhwW5tut38bJHde+3qDAVUud/INSJnTAjI9A/n3vBEZcBy+/yKvdru20 mk6Q==
- In-reply-to: <1451326987.5990.3.camel@ceramic.home.fifi.org>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <CAKc7PVBLdXYQ_NNU9q=v9TcfiZjsYKfDt2h=ZBdfGCt6t81cuQ__14537.6145992943$1450895198$gmane$org@mail.gmail.com> <20151223232519.GA9602@chaz.gmail.com> <151223210157.ZM447@torch.brasslantern.com> <1451326987.5990.3.camel@ceramic.home.fifi.org>
On Mon, Dec 28, 2015 at 7:23 PM, Philippe Troin <phil@xxxxxxxx> wrote:
> On Wed, 2015-12-23 at 21:01 -0800, Bart Schaefer wrote:
>> Further note that (MS) is sort of a dumbed-down form of backreferences,
>> returning something similar to the value of $MATCH in an extendeglob
>> pattern that uses (#m) (except extendedglob is not needed). E.g.:
>
> 8< snip >8
>
>> torch% echo ${(S)a/b*/x}
>> axcba
>> torch% echo ${(S)a//b*/x}
>> axcxa
>
> I don't understand why in these two examples the star doesn't match the
> rest of the string? I'd expect:
>
> % echo $a
> abcba
> % echo ${(S)a/b*/x}
> ax
> % echo ${(S)a//b*/x}
> ax
>
> Since b* should match the entire bcba substring.
> What did I miss?
(S) also enables shortest possible match (like # does and ## doesn't).
% a=abiibybeebz
% echo ${a/b*b/x}
axz
% echo ${(S)a/b*b/x}
axybeebz
% echo ${(S)a//b*b/x}
axyxz
% echo ${a#*b}
iibybeebz
% echo ${a##*b}
z
S Search substrings as well as beginnings or ends; with # start
from the beginning and with % start from the end of the string. With
substitution via ${.../...} or ${...//...}, specifies non-greedy
matching, i.e. that the shortest instead of the longest match should
be replaced.
--
Mikael Magnusson
Messages sorted by:
Reverse Date,
Date,
Thread,
Author