Replacing "\\ n" in Java string

I have the following piece of code:

String text = "Category:Bishopsq\\nxof La2on</target></link></sentence>\\n</paragraph><paragraph>".toString().replaceAll("(\n|\\n)", "").trim().replaceAll("\\<.*?>", " ").replaceAll("[^a-zA-Z]", " ").trim().replaceAll(" +", " ").toLowerCase();
System.out.println(text);

      

I am getting the following output:

category bishopsq nxof la on n

      

However, I need the following output:

category bishopsq xof la on

      

It replaces everything incorrectly \\n

. What am I doing wrong?

+3


source to share


1 answer


you need to escape the sign \

like:



replaceAll("(\\n|\\\\n)", "")

      

+4


source







All Articles