title: javascript regex string replace works only once
body: <p>Greetings.</p>
  
  <p>I have a function which watches the content of "price" field and updates the string in "cart" field. In "cart" field, string between | characters gets replaced with whatever is typed in "price".  My current function only works once while nothing happens on consecutive changes.  I know this is not a problem with the event itself because it works fine if I replace the entire field without regex.</p>
  
  <p>This is the format of the "cart" field and 15 needs to be replaced with content from "price" field:  <i>{nicepaypal:cart|15|New in 2010}</i>.</p>
  
  <pre><code>$('price').addEvent('keyup', function() {
      var price = $(this).value;
      var currentCartValue = $('cart').value;
      var oldPrice = String(currentCartValue.match(/\|...\|/));
      oldPrice = oldPrice.substring(1, oldPrice.length-1);  // ugly but could not get lookaheads for "between" characters to work properly
      var newCartValue = currentCartValue.replace(oldPrice, price);
      $('cart').value = newCartValue;
  });
  </code></pre>
  
  <p>Another variation does not work either:</p>
  
  <pre><code>newCartValue = currentCartValue.replace(/\|...\|/), '|'+price+'|');
  </code></pre>
  
  <p>Why is this not working when pressing a key more than once in "price" field. Thank you.</p>