Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: PATCH: Update the description of S flag in the completion



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##}
  abXXXXXXXXc

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.

Oliver



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