title: Regex to truncate trailing zeroes
body: <p>I'm trying to construct a single regex (for Java) to truncate trailing zeros past the decimal point. e.g. </p>
  
  <ul>
  <li>50.000 → 50</li>
  <li>50.500 → 50.5</li>
  <li>50.0500 → 50.05</li>
  <li>-5 → -5</li>
  <li>50 → 50</li>
  <li>5.5 → 5.5</li>
  </ul>
  
  <p>Idea is to represent the real number (or integer) in the most compact form possible.</p>
  
  <p>Here's what I've constructed:</p>
  
  <pre><code>^(-?[.0-9]+?)\.?0+$
  </code></pre>
  
  <p>I'm using <code>$1</code> to capture the truncated number string.</p>
  
  <p>The problem with the pattern above is that 50 gets truncated to 5. I need some way to express that the <code>0+</code> must follow a <code>.</code> (decimal point).<br>
  I've tried using negative-behind, but couldn't get any matches.</p>