Replacing escaped quotes in groovy

I'm not sure why this doesn't work:

  string.replaceAll('\\"','"')

      

I want to replace everything \"

with"

Any idea?

I have also tried

 string.replaceAll("[\"]","\"") 

      

+3


source to share


1 answer


The first argument to the method is a regular expression, so the backslash character matters and must be escaped. You can use the forward slash line separator to avoid double escaping. replaceAll



assert (/Hello, \"Joe\"/.replaceAll(/\\"/, '"') == 'Hello, "Joe"')

      

+3


source







All Articles