\d* allows 0 or more digits. So "." has 0 digits on both sides which is why it matches with your third regex. If you want one digit or more you can use + instead (see perlre) : /-?\d+\.\d+/$1 + 0/ge;

To avoid turning any number, you could use some of the context the number is in, like only allow the regex to match if it is not followed by a letter: s/-?\d+\.\d+(?!\w)/$1 + 0/ge; (?!reg) is a negative look-ahead assertion, it will look at what goes next to check that it does not match, but will backtrack has soon has the verification is done to not include what was just checked into the match.
s/-?\d+\.\d+(?=[)"])/$1 + 0/ge; does a similar thing the other way around, perl only allows a match that is followed by ) or ", this is a positive look-ahead assertion (once again, perl checks the rest of the string, but does not include it in the match).

Edit: s/only only/only allow/


In reply to Re: regex for trailing zeroes by Eily
in thread regex for trailing zeroes by paulbooker

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.