title: Regular expression to match numbers with or without commas and decimals in text
body: <p>I'm trying to locate and replace all numbers in a body of text.  I've found a few example regex's, which almost solve the problem, but none are perfect yet.  The problem I have is that the numbers in my text may or may not have decimals and commas.  For example:</p>
  
  <blockquote>
    <p>"The 5000 lb. fox jumped over a 99,999.99998713 foot fence." </p>
  </blockquote>
  
  <p>The regex should return "<code>5000</code>" and "<code>99,999.99998713</code>".  Examples I've found break-up the numbers on the comma or are limited to two decimal places.  I'm starting to understand regex's enough to see why some examples are limited to two decimal places, but I haven't yet learned how to overcome it and also include the comma to get the entire sequence.</p>
  
  <p>Here is my latest version: </p>
  
  <pre><code>[0-9]+(\.[0-9][0-9]?)?
  </code></pre>
  
  <p>Which returns, "<code>5000</code>", "<code>99,99</code>", "<code>9.99</code>", and "<code>998713</code>" for the above text.</p>