I just lost 1 hour to track what I consider not normal behaviour
with replaceAll/replaceFirst in the String class.
If there is a backslash in the replacement String then they are removed when
replacing. I then read that you can use Matcher.quoteReplacement(String) to
create a proper replacement string,but my question is why? I can expect that
the first argument should be escaped with Patter.quote(String) if you don't
want the special meaning but I don't see a reason to change the replacement :(
Yes I will start using replace(CharSequence,CharSequence), just want to know why :)
Here is an example that clearly shows the "strange" behaviour:
public static void main(String[] args) {
String out = "\\\\test\\\\";
System.out.println(out);
String result = "a".replaceAll("a", out);
System.out.println(result);
}
note how second line is with only single backslashes as opposed to two like in the first line