From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2024 invoked from network); 21 Mar 2001 23:00:52 -0000 Received: from sunsite.dk (130.225.51.30) by ns1.primenet.com.au with SMTP; 21 Mar 2001 23:00:52 -0000 Received: (qmail 3839 invoked by alias); 21 Mar 2001 23:00:31 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 13694 Received: (qmail 3816 invoked from network); 21 Mar 2001 23:00:30 -0000 Date: Wed, 21 Mar 2001 23:00:30 +0000 From: Adam Spiers To: Zsh hackers list Subject: Re: non-greedy matching? Message-ID: <20010321230030.A12606@thelonious.new.ox.ac.uk> Reply-To: Adam Spiers Mail-Followup-To: Zsh hackers list References: <20010321142303.B8924@thelonious.new.ox.ac.uk> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.4i In-Reply-To: ; from pws@csr.com on Wed, Mar 21, 2001 at 03:52:39PM +0000 X-Home-Page: http://www.new.ox.ac.uk/~adam/ X-OS: RedHat Linux Peter Stephenson (pws@csr.com) wrote: > Adam Spiers wrote: > > They are done in order to strip control characters from a prompt so > > that its display width can be determined. At first I thought that it > > would surely be easy to avoid this, but I still haven't come up with a > > quick replacement, since neither zsh nor sed seem to be able to do > > non-greedy matching. > > You can, it's in the manual. > > % foo='%{one%}hello%{two%}' > % print ${(S)foo//[%]\{*[%]\}} > hello *gobsmacked* I think that's the least uncomfortable I've ever felt after being RTFM'd, given that you're apparently the only -worker who remembered if that flag's existence ;-) Can I suggest that it be made slightly more self-evident in the manual, for instance via this patch? I would expect most people searching for this feature in the manual to use the keyword `greedy'. Index: Doc/Zsh/expn.yo =================================================================== RCS file: /cvsroot/zsh/zsh/Doc/Zsh/expn.yo,v retrieving revision 1.26 diff -u -r1.26 expn.yo --- Doc/Zsh/expn.yo 2001/03/12 17:39:24 1.26 +++ Doc/Zsh/expn.yo 2001/03/21 22:59:30 @@ -779,8 +779,8 @@ 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 substitution via tt(${)...tt(/)...tt(}) or -tt(${)...tt(//)...tt(}), specifies that the shortest instead of the -longest match should be replaced. +tt(${)...tt(//)...tt(}), specifies non-greedy matching, i.e. that the +shortest instead of the longest match should be replaced. ) item(tt(I:)var(expr)tt(:))( Search the var(expr)th match (where var(expr) evaluates to a number). > I just realised: //% means match only at the end. > % print ${(S)foo//\\%\{*[%]\}} > also works. Is there no limit to what zsh can do? :-)