The same backslash-mess occurs when providing replacement strings for
methods like String.replaceAll() as literal Java strings in your Java
code. In the replacement text, a dollar sign must be encoded as \$ and
a backslash as \\ when you want to replace the regex match with an
actual dollar sign or backslash. However, backslashes must also be
escaped in literal Java strings. So a single dollar sign in the
replacement text becomes <tt>"\\$"</tt> when written as a literal Java string. The single backslash becomes <tt>"\\\"</tt>. Right again: 4 backslashes to insert a single one.