Problem with string.replaceAll("\\n", " "); that is, replaceAll expects a regular expression, and \ in a regular expression is a special character used, for example, to create character classes, such as \d , which represents numbers, or to call special characters on regular expressions, such as + .
So, if you want to combine \ in a Javas regex, you need to escape twice:
- once in regex
\\ - and once in String
"\\\\" .
like replaceAll("\\\\n"," ") .
You can also let the regex engine do the escaping for you and use the replace method, for example
replace("\\n"," ")
Now, to remove \uXXXX , we can use
replaceAll("\\\\u[0-9a-fA-F]{4}","")
Also remember that Lines are immutable, so each call to str.replace.. does not affect the value of str , but creates a new line. Therefore, if you want to keep this new line in str , you will need to use
str = str.replace(..)
So your solution may look like
String text = "\"OR\\n\\nThe Central Site Engineering\\u2019s \\u201cfrontend\\u201d, where developers turn to\""; text = text.replaceAll("(\\\\n)+"," ") .replaceAll("\\\\u[0-9A-Ha-h]{4}", "");