Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: #% anchoring doesn't work with (S)
- X-seq: zsh-workers 51365
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: Zsh hackers list <zsh-workers@xxxxxxx>
- Subject: Re: #% anchoring doesn't work with (S)
- Date: Mon, 6 Feb 2023 09:17:56 -0800
- Archived-at: <https://zsh.org/workers/51365>
- In-reply-to: <CAKc7PVCqLLrq24Haa7JuUpvEdZz-VSujhsS=fdbhe37HqETBYw@mail.gmail.com>
- List-id: <zsh-workers.zsh.org>
- References: <CAKc7PVA=Beup8-GyjpxCst0=Ne_-v1yjYqn46YuRMTRuvTpteg@mail.gmail.com> <CAKc7PVBi-_jW2UZkOaxpOqUG=V+DS8sU814nVp4Yj7Su28Kqpg@mail.gmail.com> <CAHYJk3R9UGo=UTo=brTqHQnmrxTHiRxaoN1Q_9QfN4LWrsk7gQ@mail.gmail.com> <CAKc7PVCqLLrq24Haa7JuUpvEdZz-VSujhsS=fdbhe37HqETBYw@mail.gmail.com>
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