help / color / Atom feed
From: Oliver Kiddle <okiddle@yahoo.co.uk>
To: Sebastian Gniazdowski <sgniazdowski@gmail.com>
Cc: Zsh hackers list <zsh-workers@zsh.org>
Subject: Re: PATCH: Update the description of S flag in the completion
Date: Tue, 03 Dec 2019 11:39:12 +0100
Message-ID: <4702-1575369552.992754@BTqk.3315.8qcb> (raw)
In-Reply-To: <CAKc7PVDHqmBj5g3_JasumDnent5c71+-G5LhRq6LdTTuFeeEsQ@mail.gmail.com>

Sebastian Gniazdowski wrote:
> On that occasion, isn't this a bug?:
> ❯ str="ab##c#d"; print ${(S)str##\#}
> ab#c#d
> ❯ str="ab##c#d"; print ${(S)str##\##}
> ab##c#d
> Why no match at all in the second case?

It does not exhaustively find the longest match. It takes the first
possible match but matches that one greedily. The first possible match
is the empty string at the beginning of the string.

I think the following demonstrates how this works more clearly:

  % str="aXXbXXXXXXXXc"; print ${(S)str##X##}

This matches the shorter block of Xs between a and b and the greedyness
means that both Xs were matched. ${(S)str#X##} returns aXbXXXXXXXXc.


      parent reply index

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-02  0:31 Sebastian Gniazdowski
2019-12-02  0:46 ` Sebastian Gniazdowski
2019-12-03  5:16   ` Sebastian Gniazdowski
2019-12-03  9:42     ` Peter Stephenson
2019-12-03 14:45       ` Sebastian Gniazdowski
2019-12-03 10:39   ` Oliver Kiddle [this message]

Reply instructions:

You may reply publically 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:

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

  git send-email \
    --in-reply-to=4702-1575369552.992754@BTqk.3315.8qcb \
    --to=okiddle@yahoo.co.uk \
    --cc=sgniazdowski@gmail.com \
    --cc=zsh-workers@zsh.org \


* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link


Archives are clonable: git clone --mirror http://inbox.vuxu.org/zsh-workers

Example config snippet for mirrors

Newsgroup available over NNTP:

AGPL code for this site: git clone https://public-inbox.org/public-inbox.git