Reputation: 110
String i/p - Hello\n world!! \nWelcome!!
Op -
Hello
World!!
Welcome!!
If \n occurs word will be printed on the next line.
Upvotes: 0
Views: 367
Reputation: 102795
There is no need for a regular expression when wanting to replace one exact thing with one other exact thing, of course.
String in = "Hello\\nworld!!\\nWelcome!!";
String out = in.replace("\\n", "\n");
System.out.println(out);
> Hello
> World!!
> Welcome!!
If you want blank lines in between, replace with "\n\n"
instead.
Upvotes: 2