Why String.replaceAll() in java requires 4 slashes “\\\\” in regex to actually replace “\”?

You need to esacpe twice, once for Java, once for the regex.

Java code is

"\\\\"

makes a regex string of

"\\" - two chars

but the regex needs an escape too so it turns into

\ - one symbol

Leave a Comment