title: Basic regex find/replace in jQuery
body: <p>I'm very new to regex, and haven't had luck with properly selecting/replacing these strings because of the special characters involved.</p>
  
  <p>Given a form element like this:</p>
  
  <pre><code>&lt;select id="referralForm_currentReferredProducts_1__soldProductId" class="autoWidth soldProductSelect" name="currentReferredProducts[1].soldProductId"&gt;
  </code></pre>
  
  <p>How can I select the id and name attributes and increment them? Form elements are being appended to a form as HTML snippets, and I don't have the ability to implement them until they are attached to the DOM.</p>
  
  <p>Thanks!</p>
  
  <p><strong>Update:</strong>
  I've tried using <a href="http://regexpal.com/" rel="nofollow">regexpal</a> to test different expressions, this one selects the underscores correctly:
  <code>\_[0-9]+\_</code></p>
  
  <p>It just isn't actually replacing anything.. here is my code:</p>
  
  <pre><code>$.each($('#add-a-product-wrapper').children().last().find('[id*="__"]'), function(){
      $(this).attr('id').replace(/\_[0-9]+\_/, '_'+ replaceIndex +'_');
  });
  </code></pre>