zsh-workers
 help / color / mirror / code / Atom feed
From: Adam Spiers <adam@spiers.net>
To: Zsh hackers list <zsh-workers@sunsite.dk>
Subject: Re: non-greedy matching?
Date: Wed, 21 Mar 2001 23:00:30 +0000	[thread overview]
Message-ID: <20010321230030.A12606@thelonious.new.ox.ac.uk> (raw)
In-Reply-To: <Tc0a88d01526e534d4a@mailsweeper01.cambridgesiliconradio.com>; from pws@csr.com on Wed, Mar 21, 2001 at 03:52:39PM +0000

Peter Stephenson (pws@csr.com) wrote:
> Adam Spiers <adam@spiers.net> 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? :-)


  parent reply	other threads:[~2001-03-21 23:00 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20010321142303.B8924@thelonious.new.ox.ac.uk>
2001-03-21 15:52 ` Peter Stephenson
2001-03-21 16:02   ` Peter Stephenson
2001-03-21 23:00 ` Adam Spiers [this message]
2001-03-22  0:09   ` Bart Schaefer
2001-03-22 10:32     ` Peter Stephenson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20010321230030.A12606@thelonious.new.ox.ac.uk \
    --to=adam@spiers.net \
    --cc=zsh-workers@sunsite.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).