title: Insert character before specific character Java
body: <p>I have been taking a look at the regular expressions and how to use it in Java for the problem I have to solve. I have to insert a <code>\</code> before every <code>"</code>. This is what I have:</p>
  
  <pre><code>public class TestExpressions {
      public static void main (String args[]) {
  
          String test = "$('a:contains(\"CRUCERO\")')";
          test = test.replaceAll("(\")","$1%");
          System.out.println(test);
      }
  }
  </code></pre>
  
  <p>The ouput is:</p>
  
  <pre><code>$('a:contains("%CRUCERO"%)')
  </code></pre>
  
  <p>What I want is:</p>
  
  <pre><code>$('a:contains(\"CRUCERO\")')
  </code></pre>
  
  <p>I have changed <code>%</code> for <code>\\</code> but have an error <code>StringIndexOutofBounds</code> don't know why. If someone can help me I would appreciate it, thank you in advance.</p>