title: Java String.replaceAll with different match & replace criteria
body: <p>I have this code:</p>
  
  <pre><code>String polynomial = "2x^2-4x+16";
  String input = polynomial.replaceAll("[0-9a-zA-Z][-]", "+-");
  </code></pre>
  
  <p>The problem is I don't want to actually replace the <code>[0-9a-zA-Z]</code> char.</p>
  
  <p>Previously, I had used <code>polynomial.replace("-","+-");</code> but that gave incorrect output with negative powers.</p>
  
  <p>The new criteria <code>[0-9a-zA-Z][-]</code> solves the negative power issue; however it replaces a char when I only need to insert the <code>+</code> before the <code>-</code> without deleting that char.</p>
  
  <p>How can I replace this pattern using the char removed like:  </p>
  
  <pre><code>polynomial.replaceAll("[0-9a-zA-Z][-]", c+"+-");
  </code></pre>
  
  <p>where 'c' represents that <code>[0-9a-zA-Z]</code> char.</p>