* Handling of escaped plus sign ("+") in regular expressions
@ 2020-05-20 19:18 Marco Trevisan
2020-05-20 19:51 ` Eric Cook
0 siblings, 1 reply; 3+ messages in thread
From: Marco Trevisan @ 2020-05-20 19:18 UTC (permalink / raw)
To: zsh-workers
[-- Attachment #1: Type: text/plain, Size: 557 bytes --]
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.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Handling of escaped plus sign ("+") in regular expressions
2020-05-20 19:18 Handling of escaped plus sign ("+") in regular expressions Marco Trevisan
@ 2020-05-20 19:51 ` Eric Cook
2020-05-20 20:00 ` Eric Cook
0 siblings, 1 reply; 3+ messages in thread
From: Eric Cook @ 2020-05-20 19:51 UTC (permalink / raw)
To: zsh-workers
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.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Handling of escaped plus sign ("+") in regular expressions
2020-05-20 19:51 ` Eric Cook
@ 2020-05-20 20:00 ` Eric Cook
0 siblings, 0 replies; 3+ messages in thread
From: Eric Cook @ 2020-05-20 20:00 UTC (permalink / raw)
To: zsh-workers
On 5/20/20 3:51 PM, Eric Cook wrote:
> [[ +123 =~ ^\+[0-9]+$ ]]
Guessing this is the one that was excepted to return 0
in zsh [[ +123 =~ '^\+[0-9]+$' ]] would be what you wanted.
a safe way of compensate for the quoting differences of the left hand operand
is to put the ere into a variable.
pat='^\+[0-9]+$'; [[ +123 =~ $pat ]]; echo $?
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-05-20 20:01 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-20 19:18 Handling of escaped plus sign ("+") in regular expressions Marco Trevisan
2020-05-20 19:51 ` Eric Cook
2020-05-20 20:00 ` Eric Cook
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).