GNU SED (gsed) uses the same grammar as the one in CentOS or Ubuntu. I really dislike sed in Mac.
So you need to install GNU SED. Please check other places about the installment.
Then your gsed is at /opt/local/bin/gsed.
Your Mac sed is at /usr/bin/sed.
Use the following command to make a backup for Mac sed and build a soft link between gsed and sed.
sudo mv /usr/bin/sed /usr/bin/sed_backup
ln -s /opt/local/bin/gsed /usr/bin/sed
Now you may use GNU SED gsed as the default sed in Mac.