[conspire] Basic Regular Expressions (GNU/Linux "vs." BSD)
Ivan Sergio Borgonovo
mail at webthatworks.it
Thu Feb 18 02:06:08 PST 2021
Is there an -E option on BSD?
or did you try to use --posix on Linux?
On 2/18/21 10:17, Michael Paoli wrote:
> Ah, drats ... I'd expect I ought get the same from both of these, ...
> but no. Not quite sure if I'm not interpreting things exactly right,
> or there's sufficient wiggle room with BRE on this in POSIX, or there
> might possibly actually be a bug in the BSD case on this.
> But, with both grep and sed, seeing quite different results on these,
> notably BRE not matching, as in fact expected, yet on BSD matching
> where not expecting it to match:
>
> GNU/Linux:
> $ echo 'xxo o x ' | sed -ne
> '/^\(...\)\{0,2\}\([ox]\)\2\2/{s/.*/matched/p;}'
> $ echo 'xxo o x ' | grep -e '^\(...\)\{0,2\}\([ox]\)\2\2'
> $ echo 'xxo o x ' | sed -ne 's/^\(...\)\{0,2\}\([ox]\)\2\2/1:\12:\2\&:&/p'
> $
>
> BSD:
> $ echo 'xxo o x ' | sed -ne
> '/^\(...\)\{0,2\}\([ox]\)\2\2/{s/.*/matched/p;}'
> matched
> $ echo 'xxo o x ' | grep -e '^\(...\)\{0,2\}\([ox]\)\2\2'
> xxo o x
> $ echo 'xxo o x ' | sed -ne 's/^\(...\)\{0,2\}\([ox]\)\2\2/1:\12:\2\&:&/p'
> 1:xxo2:&:xxo o x
> $
>
> How can \([xo]\) matching zero characters be correct?
> That seems broken to me.
>
> But these work the same on both, as expected:
> $ echo 'xox' | grep '^\([xo]\)\1\1$'
> $ echo 'xxx' | grep '^\([xo]\)\1\1$'
> xxx
> $ echo 'xox' | sed -ne '/^\([xo]\)\1\1$/p'
> $ echo 'xxx' | sed -ne '/^\([xo]\)\1\1$/p'
> xxx
> $
>
>
> _______________________________________________
> conspire mailing list
> conspire at linuxmafia.com
> http://linuxmafia.com/mailman/listinfo/conspire
--
Ivan Sergio Borgonovo
https://www.webthatworks.it https://www.borgonovo.net
More information about the conspire
mailing list