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

Re: Handling of escaped plus sign ("+") in regular expressions



On 5/20/20 3:18 PM, Marco Trevisan wrote:
Hi,

I've been using zsh to run some local scripts I was normally running with
bash and while most of them work as expected, there's a case that weirdly
failed to me (using zsh 5.8):

[[ +123 =~ ^+[0-9]+$ ]]
zsh: failed to compile regex: Invalid preceding regular expression

[[ +123 =~ ^\+[0-9]+$ ]]
zsh: failed to compile regex: Invalid preceding regular expression

The same behavior seems to apply both using RE_MATCH_PCRE and not.
As said, both matches correctly using bash.

Using something like

[[ +123 =~ ^[+][0-9]+$ ]]

Works as expected instead.


bash's [[ =~ uses regex from the libc it was compiled against last time i checked.
and with libc's for the systems i have available, that won't work. it doesn't spit
out an error message like zsh does, but it correctly does not match the invalid regex.



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