Notice in the API that replaceAll treats the first String argument as a Regular Expression. In that context, the '$' character has special meaning to represent the end of a line. So if you want a literal '$' in your pattern, you need to use an escape sequence of \$. And in the context of a String literal, this needs an additional backslash to avoid interpretation as a Unicode escape or character escape -- that is, \\$.
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer sscce.org
Joined: Jan 30, 2000
Or, ever since JDK 1.5 you can use the replace() method rather than replaceAll(). Despite its name, the real difference is that replace() doesn't treat the first argument as a regular expression. So it's simpler, but less powerful.