AngryPanda
AngryPanda

Reputation: 1281

Replacing "\\n" in string Java

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 get the following output:

category bishopsq nxof la on n

However, I want the following output:

category bishopsq xof la on

It is not correctly replacing all \\n. What am I doing wrong?

Upvotes: 3

Views: 93

Answers (1)

gefei
gefei

Reputation: 19766

you need to escape the sign \, like this:

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

Upvotes: 4

Related Questions