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

Re: [BUG] `$match` is haunting my regex’s trailing, optional, capture



On Fri, Dec 8, 2023 at 9:14 PM <chris0e3@xxxxxxxxx> wrote:
>
>   setopt rematch_pcre
>   [[ 'REQUIRE. OPT' =~ 'REQUIRE.(\s*OPT)?' ]] && printf '\tA. ‹%s›\n' $match
>   [[ 'REQUIRE.'     =~ 'REQUIRE.(\s*OPT)?' ]] && printf '\tB. ‹%s›\n' $match

Aside, you should use e.g. "$match[@]" there (including the quotes) or
you'll be surprised when there is more than one back reference.

> It looks like: if there is a match, but no captures are matched then `$match` is not cleared.

The output of your latter example is certainly not consistent with e.g.

 setopt extendedglob
 [[ 'REQUIRE.' = (#b)REQUIRE.(*OPT)(#c0,1) ]] && printf '\tB. ‹%s›\n' $match

And I can reproduce your example with the most recent git checkout, as
well.  Oliver recently updated to pcre2, so if a patch appears, you
may be on your own to backport it.




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