Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: [PATCH] zshexpn: Expand documentation of (S) (was: Re: [Bug] S-flag imposes non-greedy match where it shouldn't)
- X-seq: zsh-workers 45162
- From: Roman Perepelitsa <roman.perepelitsa@xxxxxxxxx>
- To: Sebastian Gniazdowski <sgniazdowski@xxxxxxxxx>
- Subject: Re: [PATCH] zshexpn: Expand documentation of (S) (was: Re: [Bug] S-flag imposes non-greedy match where it shouldn't)
- Date: Mon, 30 Dec 2019 21:01:47 +0100
- Cc: Zsh hackers list <zsh-workers@xxxxxxx>, Daniel Shahaf <d.s@xxxxxxxxxxxxxxxxxx>
- In-reply-to: <CAKc7PVAXLpKqZvmbazZK=mvcz8T-AHJXKusut6aEjkkSLzgdbw@mail.gmail.com>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- List-unsubscribe: <mailto:zsh-workers-unsubscribe@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <CAKc7PVCUBKfsOSakwNwrcx1Xkf09b5CFJJDxjKFYU42oAUFZ-g@mail.gmail.com> <CAKc7PVCPPeE36W4aSKu5rid2Vem+Q+h5XZTX+k7=E9qLU0nPhw@mail.gmail.com> <1a130b2e-5824-4b7a-8510-2b1d0b3fdac5@www.fastmail.com> <CAKc7PVDOMz1wvMGWYOki7ca5dHodMJx30eq8UEzgj=D+W7E4aQ@mail.gmail.com> <20191227052923.yal2nnmxdxfgvfkr@tarpaulin.shahaf.local2> <CAKc7PVDx6WEFcZFS3TQ6+rF1YpA3jkD5sWwr0LCNE_c5MYkxVg@mail.gmail.com> <20191228210017.2cdgwgpqrssrfhgp@tarpaulin.shahaf.local2> <CAKc7PVD7UCc5yqDays=xCVFa=-Ns6phhqLd2se_+3iKNzOr5tA@mail.gmail.com> <20191229020534.oqh5ri3nqealx4hj@tarpaulin.shahaf.local2> <CAKc7PVDhkOm9gQ-mxRnyh=MT_onqvsQAzymcpV+AguanHa7nig@mail.gmail.com> <20191230180036.u33ixxe5pjjk7lal@tarpaulin.shahaf.local2> <CAN=4vMor_OBci8FRDkQjM8GfpGuM2A58D=nN+WoDgpQrpRKBzg@mail.gmail.com> <CAKc7PVAXLpKqZvmbazZK=mvcz8T-AHJXKusut6aEjkkSLzgdbw@mail.gmail.com>
On Mon, Dec 30, 2019 at 8:32 PM Sebastian Gniazdowski
<sgniazdowski@xxxxxxxxx> wrote:
>
> Do you also understand why:
>
> str=aXXXb
> print ${str%%X##}
>
> Outputs aXXb?
I suppose you mean ${(S)str%%X##}. Yes, I understand why this prints aXXb.
> Outputs aXXb? The docs don't cover this.
They do with the latest patch for (S) from Daniel:
> With tt(%) or tt(%%), search for the match that starts closest to the end of
> the string
This means that ${(S)str%%X##} is going to find a match that starts
closest to the end of the string and remove it. X## matches one or
move X characters. We go backwards one character at a time until X##
matches. The first match starts at str[-2] and the match is X, so X
gets removed. This seems clear from the docs.
I think it would be beneficial to specify that with ${(S)str##pattern}
the first attempted match starts at str[-1] and that no attempt is
made to check if the empty string (the ultimate shortest suffix)
matches. I think you or someone else has recently raised this point as
this seems inconsistent. It's surprising to me that both ${str#*} and
${(S)str%*} expand to $str while ${(S)str%%*} doesn't.
Roman.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author