Then you will have to do it in the variables contents. You could write a library function (make_regexp()) out of it, which gets a string and escapes it properly:
function pMakeRegexp
{
if [ $# -ne 1 ] ; then
return 1
fi
# add to the characters in the bracket if i have overlooked one
print - "$1" | sed 's/[/\&^*.$]/\\&/g'
return 0
}
# main
typeset var="some \ special ^ characters / are & here"
typeset regex_var="$(pMakeRegexp "$var")"
print - "var is \"$var\" // regexed var is \"$regex_var\""
print - "xx $var xx" | sed "s/$regex_var/=&=/"
exit 0
As you can see the regexed version "$regex_var" matches normal version "$var" and the replacement (adding the equal signs before and after) is taking place. Similarily you can put the replacement string through pMakeRegexp() too.