# Getting different results from sed on FreeBSD 12.2 vs. FreeBSD 13.0 vs. Linux



## Echoxxzz (Jul 21, 2021)

Trying to use extended regular expressions and I'm getting mixed results (neither of which is correct) between FreeBSD 12.2 and 13.0 vs Linux (working).

FreeBSD 12.2:


> # echo 'abcd' | sed -r 's/(\w)(.*)/\1/'
> abcd



FreeBSD 13.0:


> # echo 'abcd' | sed -r 's/(\w)(.*)/\1/'
> sed: 1: "s/(\w)(.*)/\1/": RE error: trailing backslash (\)



Linux:


> # echo 'abcd' | sed -r 's/(\w)(.*)/\1/'
> a



Can someone tell me what I'm doing wrong?

Update: If I install 'gsed' it works perfectly!!!


----------



## gpw928 (Jul 21, 2021)

The FreeBSD 13 Release Notes mention this change which explains the difference from FreeBSD 12.

When it comes to "extended" regular expressions, I always disambiguate as you have, by using a tool with well documented behaviour, like `perl` or `gsed`.


----------



## Echoxxzz (Jul 21, 2021)

I porting all my bash scripts to FreeBSD so I suppose I better not trust the builtin awk and I better install and use gawk instead.


----------



## covacat (Jul 21, 2021)

\w is not supported (see re_format(7))
use [:alnum:] and it will work


----------

