remram44 / regex-cheatsheet

Cheatsheet for different regex syntaxes
https://remram44.github.io/regex-cheatsheet/regex.html
278 stars 64 forks source link

sed ERE switch is -r #11

Closed d-nnis closed 7 years ago

d-nnis commented 7 years ago

The last line in the last table is false on the website. The ERE switch for sed to use extended regular expressions is -r or --regexp-extended

man sed sais

   -r, --regexp-extended
         use extended regular expressions in the script.
remram44 commented 7 years ago

Most platforms I found accept -E, though it might not be the POSIX standard. MacOS however only accepts -E, not -r. Do you have a version of send that doesn't accept -E?

remram44 commented 7 years ago

(Actually POSIX doesn't mention EREs or either flag at all)

d-nnis commented 7 years ago

That is weird. man sed states this for sed 4.2.2 on Linux edgar 3.16.0-4-amd64 #1 SMP Debian 3.16.39-1+deb8u2 (2017-03-07) x86_64 GNU/Linux

d-nnis commented 7 years ago

So far I found it here. The manual from the gnu-website mentions both -r and -E.

d-nnis commented 7 years ago

Hmm. And actually sed -E works as well, though it is not documented in the man available offline on my system. echo "something" | sed -E 's/(o)/\1T/'

soTmething

So you might just leave it on your website...

remram44 commented 7 years ago

So -E seems to be the BSD flag (also accepted by GNU sed) and -r the GNU flag (though it is accepted by some BSD versions).

On FreeBSD, the manual reads:

-r Same as -E for compatibility with GNU sed.

So I'm going to keep -E in the table. Thanks for looking at this!