in reply to regex for trailing zeroes

\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/

Replies are listed 'Best First'.
Re^2: regex for trailing zeroes
by paulbooker (Initiate) on Feb 23, 2016 at 12:58 UTC

    Thank you, Eily and choroba, that works for me

    Important lesson learnt!