Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: non-greedy matching?
- X-seq: zsh-workers 13694
- From: Adam Spiers <adam@xxxxxxxxxx>
- To: Zsh hackers list <zsh-workers@xxxxxxxxxx>
- Subject: Re: non-greedy matching?
- Date: Wed, 21 Mar 2001 23:00:30 +0000
- In-reply-to: <Tc0a88d01526e534d4a@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx>; from pws@xxxxxxx on Wed, Mar 21, 2001 at 03:52:39PM +0000
- Mail-followup-to: Zsh hackers list <zsh-workers@xxxxxxxxxx>
- Mailing-list: contact zsh-workers-help@xxxxxxxxxx; run by ezmlm
- References: <Tc0a88d01526e534d4a@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx> <Tc0a88d01526e5c5083@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx> <20010321142303.B8924@xxxxxxxxxxxxxxxxxxxxxxx> <Tc0a88d01526e534d4a@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx>
- Reply-to: Adam Spiers <adam@xxxxxxxxxx>
Peter Stephenson (pws@xxxxxxx) wrote:
> Adam Spiers <adam@xxxxxxxxxx> 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? :-)
Messages sorted by:
Reverse Date,
Date,
Thread,
Author