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

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



> On 06/02/2023 17:17 Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
> 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.

I haven't followed this through in detail, but I believe we just don't have
enough state in the matcher to deal with longest vs. shortest substring
at the same time as everything else.

pws




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