title: Using Regular Expressions with Javascript replace method
body: <p>Friends, </p>
  
  <p>I'm new to both Javascript and Regular Expressions and hope you can help! </p>
  
  <p>Within a Javascript function I need to check to see if a comma(,) appears 1 or more times. If it does then there should be one or more numbers either side of it.  </p>
  
  <p>e.g.</p>
  
  <p>1,000.00 is ok</p>
  
  <p>1,000,00 is ok </p>
  
  <p>,000.00 is not ok</p>
  
  <p>1,,000.00 is not ok</p>
  
  <p>If these conditions are met I want the comma to be removed so 1,000.00 becomes 1000.00 </p>
  
  <p>What I have tried so is:</p>
  
  <p>var x = '1,000.00';</p>
  
  <p>var regex = new RegExp("[0-9]+,[0-9]+", "g");</p>
  
  <p>var y = x.replace(regex,"");       </p>
  
  <p>alert(y);       </p>
  
  <p>When run the alert shows ".00" Which is not what I was expecting or want!</p>
  
  <p>Thanks in advance for any help provided.</p>
  
  <p><strong>strong text</strong>
  Edit
  <strong>strong text</strong></p>
  
  <p>Thanks all for the input so far and the 3 answers given. Unfortunately I don't think I explained my question well enough. </p>
  
  <p>What I am trying to achieve is:</p>
  
  <p>If there is a comma in the text and there are one or more numbers either side of it then remove the comma but leave the rest of the string as is. </p>
  
  <p>If there is a comma in the text and there is not at least one number either side of it then do nothing.</p>
  
  <p>So using my examples from above:    </p>
  
  <p>1,000.00 becomes 1000.00</p>
  
  <p>1,000,00 becomes 100000</p>
  
  <p>,000.00 is left as ,000.00</p>
  
  <p>1,,000.00 is left as 1,,000.00</p>
  
  <p>Apologies for the confusion!</p>