I have a string andn I want to replace { to \{ ... When I use replace method then it works but when I use replaceAll then it is giving error like Illegal repetition
What is the reason?
String s = "One{ two } three {{{ four}";
System.out.println(s.replace("{", "\\{"));
System.out.println(s.replaceAll("{", "\\{"));
Expected output is - One\{ two } three \{\{\{ four}
s.replaceAll("\\{", "\\\\{")