replaceAllの罠

久々にあらっと思ったのでメモ
String#replaceAll(String regex, String replacement)は正規表現を受け取るのでregex部分に特殊文字を埋め込む場合エスケープしないといけないのは当然の話なのですが、replacement部分もエスケープされてしまう。
JavaDocにもかいてあった。

Note that backslashes (\) and dollar signs ($) in the replacement string may cause the results to be different than if it were being treated as a literal replacement string; see Matcher.replaceAll. Use Matcher.quoteReplacement(java.lang.String) to suppress the special meaning of these characters, if desired.

にしても以下2行が同じになるとは判断しにくいしまぎらわしい!

	"Garapon".replaceAll("a", ".");
	"Garapon".replaceAll("a", "\\.");