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

Re: #% anchoring doesn't work with (S)



On Thu, Feb 2, 2023 at 4:49 AM Sebastian Gniazdowski
<sgniazdowski@xxxxxxxxx> wrote:
> On Thu, 2 Feb 2023 at 10:32, Mikael Magnusson <mikachu@xxxxxxxxx> wrote:
>>
>> Why would you use (S) (shortest possible match) with #% (match the
>> entire string)? It will obviously never have a useful effect other
>> than doing nothing.
>
> It does have sense to match shortest and anchor to #%, it simply moves the "weight" on the right side of the pattern, i.e. "ABC" == (?)* vs ABC == *(?) (not very correct, but shows the thought).

Arguably then this is wrong:

% sample=match
% : ${(S)sample/(#b)(#s)(m*)(*)(#e)}; printf "<%s>" $match ; echo
<match>

I expected <m><atch>.  Compare without the end anchor:

% : ${(S)sample/(#b)(#s)(m*)(*)}; printf "<%s>" $match ; echo
<m>

In any case the behavior of PWS's patch appears to be the same.

Also

% : ${(S)sample/(#b)(#s)(m*)(*h)}; printf "<%s>" $match ; echo
<matc><h>

I guess it's ambiguous, but in other patterns like (this|that) we
prefer the left before the right.




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