title: Javascript (or jQuery) string replacement
body: <p>So, I have strings pulled from a JSON array like this:</p>
  
  <pre><code>Hg22+
  CO32-
  Al3Cl23+
  </code></pre>
  
  <p>These numbers need to be superscript or subscript, with rules.  It's only numbers 0-9, and if that number has a plus or minus after it, it needs to be superscript, meaning I need to change the string to <code>&lt;sup&gt;3+&lt;/sup&gt;</code>.  All other numbers, if they haven't been superscripted, need to be subscripted.  Here are a few examples of what I need:</p>
  
  <p><code>C12H22O11 (s, sucrose)</code> = <code>&lt;sub&gt;1&lt;/sub&gt;&lt;sub&gt;2&lt;/sub&gt;H&lt;sub&gt;2&lt;/sub&gt;&lt;sub&gt;2&lt;/sub&gt;O&lt;sub&gt;1&lt;/sub&gt;&lt;sub&gt;1&lt;/sub&gt; (s, sucrose)</code></p>
  
  <p><code>Al3Cl23+</code> = <code>Al&lt;sub&gt;3&lt;/sub&gt;Cl&lt;sub&gt;2&lt;/sub&gt;&lt;sup&gt;3+&lt;/sup&gt;</code></p>
  
  <p><code>Hg22+</code> = <code>Hg&lt;sub&gt;2&lt;/sub&gt;&lt;sup&gt;2+&lt;/sup&gt;</code></p>
  
  <p>I can do it, but very sloppily.  I am really open to a good way to change string like above.  If anyone can help out I'd be really appreciative!</p>
  
  <p>Thanks!</p>