From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 20739 invoked by alias); 28 Dec 2015 19:13:10 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 21105 Received: (qmail 6223 invoked from network); 28 Dec 2015 19:13:09 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM, T_DKIM_INVALID autolearn=ham autolearn_force=no version=3.4.0 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== MIME-Version: 1.0 X-Received: by 10.55.27.93 with SMTP id b90mr32802292qkb.51.1451329985832; Mon, 28 Dec 2015 11:13:05 -0800 (PST) In-Reply-To: <1451326987.5990.3.camel@ceramic.home.fifi.org> References: <20151223232519.GA9602@chaz.gmail.com> <151223210157.ZM447@torch.brasslantern.com> <1451326987.5990.3.camel@ceramic.home.fifi.org> Date: Mon, 28 Dec 2015 20:13:05 +0100 Message-ID: Subject: Re: Example of use of (S) flag From: Mikael Magnusson To: Philippe Troin Cc: Zsh Users Content-Type: text/plain; charset=UTF-8 On Mon, Dec 28, 2015 at 7:23 PM, Philippe Troin 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