I've updated the trick. It's now: str="abcXXXdefXXXghi" out=${(S)str%%(#b)([^X])X##(*)} out=$out$match[1]$match[2] The man page looks like http://psprint.blinkenshell.org/S_flag-2.png I think that the trick is minimal to get the job done, i.e.: to actually match a substring greedily starting from the right. On Fri, 27 Dec 2019 at 05:54, Sebastian Gniazdowski wrote: > > The trick is not right. I'll try to update it or otherwise change the > description. > > On Thu, 26 Dec 2019 at 19:35, Sebastian Gniazdowski > wrote: > > > > I've attached the extended description. It includes a trick to > > work-around the unintuitive behavior of S. It looks as follows: > > > > http://psprint.blinkenshell.org/S_flag.png > > > > I think that the way the S flag works is a bit of an inconsistency, > > Because ${str%%X##**} would not stop at the first from the right > > match, it would try other matches starting from the right and go on up > > to the final first from the left X. I think that (S) shouldn't change > > this, but on the other hand should ${(S)str%%X##} match the first > > three X? Rather not, as it would resemble ## then... Intuitively, > > however, it should match all the three right X. > > > > On Thu, 19 Dec 2019 at 16:30, Daniel Shahaf wrote: > > > > > > Sebastian Gniazdowski wrote on Wed, 18 Dec 2019 20:44 +00:00: > > > > Or rather not a bug… It seems that it's the result of how % searches > > > > the substrings from the end – it stops at the first match, i.e.: after > > > > finding a first X from the right. > > > > > > Could we improve the documentation of (S), then? > > > > > > > > -- > > Sebastian Gniazdowski > > News: https://twitter.com/ZdharmaI > > IRC: https://kiwiirc.com/client/chat.freenode.net:+6697/#zplugin > > Blog: http://zdharma.org > > > > -- > Sebastian Gniazdowski > News: https://twitter.com/ZdharmaI > IRC: https://kiwiirc.com/client/chat.freenode.net:+6697/#zplugin > Blog: http://zdharma.org -- Sebastian Gniazdowski News: https://twitter.com/ZdharmaI IRC: https://kiwiirc.com/client/chat.freenode.net:+6697/#zplugin Blog: http://zdharma.org