Why does this code not work?
public static void main(String[] args) {
String s = "You need the new version for this. Please update app ...";
System.out.println(s.replaceAll(". ", ".\\\\n").replaceAll(" ...", "..."));
}
This is my wanted output:
You need the new version for this.\nPlease update app…
Thanks for the information
String.replaceAllmethod takes Regex as first argument.So you need to escape your dot (
.), as it has special meaning in Regex, which matches any character.However, for your given input, you can simply use
String.replacemethod, as it does not takeRegex, and has an added advantage of that.