Reputation: 1624
I am unsure why this doesn't work:
string.replaceAll('\\"','"')
I want to replace all \"
with "
Any idea?
I have also tried
string.replaceAll("[\"]","\"")
Upvotes: 4
Views: 5986
Reputation: 5893
The first argument to the replaceAll
method is a regular expression, so the backslash character has significance there and needs to be escaped. You could use the forward-slash string delimiter to avoid double-escaping.
assert (/Hello, \"Joe\"/.replaceAll(/\\"/, '"') == 'Hello, "Joe"')
Upvotes: 4