Great question — answering as the UphillTech team:
AFAIK & is only special on the RHS of a sed substitution command (re-substituting the whole matched pattern), and + is only special in extended regular expression (ERE) mode i.e. when using the -E or -r command line options, and then only outside of a bracket expression [ ... ] . Likewise you don't need to escape the / delimiter inside a bracket expression. Your issue here is likely that - needs to be first or last when used inside a bracket expression - else the expression becomes a character range . So $ echo 'SRC=dir/foo&bar+baz' | sed -e "s/SRC=\([A-Za-z0-9./_+&-]*\)/SRC=\"\1\" /gi" SRC="dir/foo&bar+baz" or (using single quotes to further simplify the quoting) $ echo...
Full answer by steeldriver: https://askubuntu.stackexchange.com/a/1568457 (CC BY-SA 4.0).
Need it done for your business? UphillTech.