You can;t do that in a single regex - you can detect "either/or" but you can't specify different replacements depending on which "catch" you get in a single replace operation.
So do it with two operations:
\$\b
will catch the "$" at the start of a word, and
\b\$
will catch the end.