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=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 ef7f8960 for ; Mon, 30 Dec 2019 18:01:25 +0000 (UTC) Received: (qmail 18106 invoked by alias); 30 Dec 2019 18:01:18 -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: 45160 Received: (qmail 26485 invoked by uid 1010); 30 Dec 2019 18:01:18 -0000 X-Qmail-Scanner-Diagnostics: from wout5-smtp.messagingengine.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(64.147.123.21):SA:0(-2.6/5.0):. Processed in 4.159305 secs); 30 Dec 2019 18:01:18 -0000 X-Envelope-From: d.s@daniel.shahaf.name X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: none (ns1.primenet.com.au: domain at daniel.shahaf.name does not designate permitted sender hosts) X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedufedrvdefhedguddtjecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecuogfggedutddqvdejucdlgedtmdenucfjughrpe ffhffvuffkfhggtggujggfsehttddttddtredvnecuhfhrohhmpeffrghnihgvlhcuufhh rghhrghfuceougdrshesuggrnhhivghlrdhshhgrhhgrfhdrnhgrmhgvqeenucfkphepje elrddukedtrdehjedrudduleenucfrrghrrghmpehmrghilhhfrhhomhepugdrshesuggr nhhivghlrdhshhgrhhgrfhdrnhgrmhgvnecuvehluhhsthgvrhfuihiivgeptd X-ME-Proxy: Date: Mon, 30 Dec 2019 18:00:36 +0000 From: Daniel Shahaf To: Zsh hackers list Subject: [PATCH] zshexpn: Expand documentation of (S) (was: Re: [Bug] S-flag imposes non-greedy match where it shouldn't) Message-ID: <20191230180036.u33ixxe5pjjk7lal@tarpaulin.shahaf.local2> References: <1a130b2e-5824-4b7a-8510-2b1d0b3fdac5@www.fastmail.com> <20191227052923.yal2nnmxdxfgvfkr@tarpaulin.shahaf.local2> <20191228210017.2cdgwgpqrssrfhgp@tarpaulin.shahaf.local2> <20191229020534.oqh5ri3nqealx4hj@tarpaulin.shahaf.local2> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20170113 (1.7.2) --- Sebastian Gniazdowski wrote on Sun, Dec 29, 2019 at 04:14:11 +0100: > Rather not, I've couldn't replace the example with anything simpler > and the patch that would describe the issue with (S) would be either > superficial (for a short version) or too long and convoluted. diff --git a/Doc/Zsh/expn.yo b/Doc/Zsh/expn.yo index d7147dbd7..92687bcfe 100644 --- a/Doc/Zsh/expn.yo +++ b/Doc/Zsh/expn.yo @@ -1394,11 +1394,40 @@ used with the tt(${)...tt(/)...tt(}) forms. startitem() item(tt(S))( -Search substrings as well as beginnings or ends; with tt(#) start -from the beginning and with tt(%) start from the end of the string. +With tt(#) or tt(##), search for the match that starts closest to the start of +the string (a `substring match'). Of all matches at a particular position, +tt(#) selects the shortest and tt(##) the longest: + +example(% str="aXbXc" +% echo ${+LPAR()S+RPAR()str#X*} +abXc +% echo ${+LPAR()S+RPAR()str##X*} +a +% ) + +With tt(%) or tt(%%), search for the match that starts closest to the end of +the string: + +example(% str="aXbXc" +% echo ${+LPAR()S+RPAR()str%X*} +aXbc +% echo ${+LPAR()S+RPAR()str%%X*} +aXb +% ) + +(Note that tt(%) and tt(%%) don't search for the match that ends closest to the +end of the string, as one might expect.) + With substitution via tt(${)...tt(/)...tt(}) or tt(${)...tt(//)...tt(}), specifies non-greedy matching, i.e. that the -shortest instead of the longest match should be replaced. +shortest instead of the longest match should be replaced: + +example(% str="abab" +% echo ${str/*b/_} +_ +% echo ${+LPAR()S+RPAR()str/*b/_} +_ab +% ) ) item(tt(I:)var(expr)tt(:))( Search the var(expr)th match (where var(expr) evaluates to a number). Cheers, Daniel