Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

replacing escaped quotes in groovy

I am unsure why this doesn't work:

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

I want to replace all \" with "

Any idea?

I have also tried

 string.replaceAll("[\"]","\"") 
like image 629
Sagarmichael Avatar asked Sep 09 '25 12:09

Sagarmichael


1 Answers

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"')
like image 70
bdkosher Avatar answered Sep 12 '25 03:09

bdkosher