简体   繁体   中英

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?

你需要逃避标志\\ ,像这样:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM