2

How can i remove special character "\" in the string below:

String x = {
    "message": {
        "@content": "toom"
    },
    "recipients": "[{\"@id\":\"1000001865\"}]",
    "room": {
        "@subject": "room"
    }
}

I used x.replaceAll("\\","") but it does not work.

user3115198
  • 107
  • 2
  • 3
  • 8

1 Answers1

6

You must escape the backslash in the regex.

try

x.replaceAll("\\\\", "")

see JavaRegularExpressions: 3.6. Backslashes in Java

Balder
  • 8,623
  • 4
  • 39
  • 61