title: How to replace last occurrence of characters in a string using javascript
body: <p>I'm having a problem finding out how to replace the last ', ' in a string with ' and ':</p>
  
  <p>Having this string:
  test1, test2, test3</p>
  
  <p>and I want to end out with:
  test1, test2 and test3</p>
  
  <p>I'm trying something like this:</p>
  
  <pre><code>var dialog = 'test1, test2, test3';    
  dialog = dialog.replace(new RegExp(', /g').lastIndex, ' and ');
  </code></pre>
  
  <p>but it's not working</p>