I can replace dollar signs by using Matcher.quoteReplacement. I can replace words by adding boundary characters:
Matcher.quoteReplacement.
from = \"\\\\b\" + from + \"\
Matcher.quoteReplacement() is for the replacement string (to), not the regex (from). To include a string literal in the regex, use Pattern.quote():
Matcher.quoteReplacement()
to
from
Pattern.quote()
from = Pattern.quote(from);