title: Double-escaping regex from inside a Groovy expression
body: <p><strong>Note</strong>: I had to simplify my actual use case to spare SO a lot of backstory. So if your first reaction to this question is: <em>why would you ever do this</em>, trust me, I just need to.</p>
  
  <p>I'm trying to write a Groovy expression that replaces double-quotes ("<code>"</code>") that appear in a string with single-quotes ("<code>'</code>").</p>
  
  <pre><code>// BEFORE: Replace my "double" quotes with 'single' quotes.
  String toReplace = "Replace my \"double-quotes\" with 'single' quotes.";
  
  // Wrong: compiler error
  String replacerExpression = "toReplace.replace(""", "'");";
  
  Binding binding = new Binding();
  binding.setVariable("toReplace", toReplace);
  GroovyShell shell = new GroovyShell(binding);
  
  // AFTER: Replace my 'double' quotes with 'single' quotes.
  String replacedString = (String)shell.evaluate(replacerExpression);
  </code></pre>
  
  <p>The problem is, I'm getting a compile error on the line where I assign <code>replacerExpression</code>:</p>
  
  <blockquote>
    <p>Syntax error on token ""toReplace.replace("", { expected</p>
  </blockquote>
  
  <p>I think it's because I need to escape the string that contains the double-quote character (""") but since it's a string-inside-a-string, I'm not sure how to properly escape it here. Any ideas? Thanks in advance!</p>