$ pattern='[^a-zA-Z0-9]'
$ echo "123 ABC" | sed "s/$pattern/g"
sed: -e expression #1, char 16: unterminated 's' command
$ echo "123 ABC" | sed "s/$pattern//g"
123ABC
$ echo "123 ABC" | sed "s/$pattern/XYZ/g"
123XYZABC
E ...
Shell variables are assigned without a leading
$
.