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)



On Mon, 30 Dec 2019 at 21:01, Roman Perepelitsa
<roman.perepelitsa@xxxxxxxxx> wrote:
> 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.

Ok, this does seem to capture the issue.

> 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.

Also, ${str%*} doesn't expand to $str, which seems to be a bug? Is it
a different uncover of the one from users/22600?


--
Sebastian Gniazdowski
News: https://twitter.com/ZdharmaI
IRC: https://kiwiirc.com/client/chat.freenode.net:+6697/#zplugin
Blog: http://zdharma.org



Messages sorted by: Reverse Date, Date, Thread, Author