From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=DKIM_ADSP_CUSTOM_MED, FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from primenet.com.au (ns1.primenet.com.au [203.24.36.2]) by inbox.vuxu.org (OpenSMTPD) with ESMTP id a456a138 for ; Mon, 30 Dec 2019 20:02:41 +0000 (UTC) Received: (qmail 1499 invoked by alias); 30 Dec 2019 20:02:33 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: List-Unsubscribe: X-Seq: 45162 Received: (qmail 5343 invoked by uid 1010); 30 Dec 2019 20:02:33 -0000 X-Qmail-Scanner-Diagnostics: from mail-il1-f194.google.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.102.1/25677. spamassassin: 3.4.2. Clear:RC:0(209.85.166.194):SA:0(-2.0/5.0):. Processed in 1.239689 secs); 30 Dec 2019 20:02:33 -0000 X-Envelope-From: roman.perepelitsa@gmail.com X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: pass (ns1.primenet.com.au: SPF record at _netblocks.google.com designates 209.85.166.194 as permitted sender) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=itXpv2u41ruiYFo1Be34gGFmSPsKbpPlMxfBCv4JGsQ=; b=MRvRHF265EAKfPiWWhuvFPU7Qdrni1myvU4AXvw/E9dEJ5QvtKiaaQPSqp575+5CE3 N4ScJB8XY5FUC9oSUJ5RAn5IuUN7PX+xaRD0H0Z8oGjzmqSA3yd9lqjb1ocPK0Ji16sS FVZO7L/49T3NoCwbPFswngsge68MgS+Gi+MRejJbwOveIUonhuNmGefbZyiXs4Y2/NCw wmuj0NYGR/Mn+llUopBzoke9DIGPplWz3Xl56qORvr/aZ866g9F+w0MjU/XndNXnwPs2 dnxV8UJMcwuzBCa+Ob7dPf3mc+3H/T275elrn2xom19lSeG95NObUSPcQS9s+LUQypR8 PVhw== X-Gm-Message-State: APjAAAXenaaKTNc404W587SgXgG99MZbI+Pc8OZ8aSgSGgNZ6ymPmkLd pBTH2nwfT0+btrBRJHGMy+TW8J1IoALXXbFLAZ/G3q2lotI= X-Google-Smtp-Source: APXvYqw7xWikOyRDcVK7LXR3FLV2Mka1iwzj/O5YU8d0XQnWvYwEhS90k0bYmCdvG5bRO3C0ajB6oXpuDPfFQ2VFbSw= X-Received: by 2002:a92:d642:: with SMTP id x2mr58331399ilp.169.1577736118592; Mon, 30 Dec 2019 12:01:58 -0800 (PST) MIME-Version: 1.0 References: <1a130b2e-5824-4b7a-8510-2b1d0b3fdac5@www.fastmail.com> <20191227052923.yal2nnmxdxfgvfkr@tarpaulin.shahaf.local2> <20191228210017.2cdgwgpqrssrfhgp@tarpaulin.shahaf.local2> <20191229020534.oqh5ri3nqealx4hj@tarpaulin.shahaf.local2> <20191230180036.u33ixxe5pjjk7lal@tarpaulin.shahaf.local2> In-Reply-To: From: Roman Perepelitsa Date: Mon, 30 Dec 2019 21:01:47 +0100 Message-ID: Subject: Re: [PATCH] zshexpn: Expand documentation of (S) (was: Re: [Bug] S-flag imposes non-greedy match where it shouldn't) To: Sebastian Gniazdowski Cc: Zsh hackers list , Daniel Shahaf Content-Type: text/plain; charset="UTF-8" On Mon, Dec 30, 2019 at 8:32 PM Sebastian Gniazdowski wrote: > > Do you also understand why: > > str=aXXXb > print ${str%%X##} > > Outputs aXXb? I suppose you mean ${(S)str%%X##}. Yes, I understand why this prints aXXb. > Outputs aXXb? The docs don't cover this. They do with the latest patch for (S) from Daniel: > With tt(%) or tt(%%), search for the match that starts closest to the end of > the string This means that ${(S)str%%X##} is going to find a match that starts closest to the end of the string and remove it. X## matches one or move X characters. We go backwards one character at a time until X## matches. The first match starts at str[-2] and the match is X, so X gets removed. This seems clear from the docs. I think it would be beneficial to specify that with ${(S)str##pattern} the first attempted match starts at str[-1] and that no attempt is made to check if the empty string (the ultimate shortest suffix) matches. I think you or someone else has recently raised this point as this seems inconsistent. It's surprising to me that both ${str#*} and ${(S)str%*} expand to $str while ${(S)str%%*} doesn't. Roman.