I recently noticed that, String.replaceAll(regex,replacement) behaves very weirdly when it comes to the escape-character \"\\\"(slash)
For example consider there is
One way around this problem is to replace backslash with another character, use that stand-in character for intermediate replacements, then convert it back into backslash at the end. For example, to convert "\r\n" to "\n":
String out = in.replace('\\','@').replaceAll("@r@n","@n").replace('@','\\');
Of course, that won't work very well if you choose a replacement character that can occur in the input string.