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

Re: Pattern bug on (a*|)~^(*b)



On Tue, Jul 25, 2023 at 6:19 AM Johan Grande <nahoj@xxxxxxxxx> wrote:
>
> In zsh 5.8.1 (x86_64-ubuntu-linux-gnu) with extended_glob,
>
> [[ "ab" = (|a*)~^(*b) ]]
>
> incorrectly (unless I'm mistaken) returns 1.

This is not precisely a bug, it's expected behavior.  Alternation with
(x|y) tries the patterns in left-to-right order and has lower
precedence than p~q (despite the parens).  The upshot is that
(|a*)~^(*b) matches like (|)~^(*b) whereas (a*|)~^(*b) is like
(a*)~^(*b) and the final bit of the puzzle is that the double negative
in  ~^(b*) cannot match the empty result from (|).

The same thing happens with globbing, touch a file named "ab" and then
try those patterns for filename generation.  PWS may be able to
explain some more about the precedence of (x|y) vs. (p~q).

To resolve this, you have to put the p~q inside the x|y, like [[ "ab"
= (|a*~^(*b)) ]]




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