help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Regex replace for numbers


From: Robert Thorpe
Subject: Re: Regex replace for numbers
Date: Fri, 03 Oct 2014 02:41:32 +0100

Marcin Borkowski <mbork@wmi.amu.edu.pl> writes:
> On 2014-10-03, at 02:33, Robert Thorpe wrote:
>
>> I'm not very good with Emacs regex, I need to search-and-replace on some 
>> numbers.
>>
>> How can I detect unnecessary zeros at the end of a number and chop them
>> off?  E.g. turn 567.45000 to 567.45 without also turning 6700 to 67.
>
> What about
>
> M-%
> \([0-9]+\)\.\([0-9]*?\)0+   RET
> \1.\2    RET

That needs C-M-%, regexp-replace.  If I have a number like 456.0040 then
it replaces the first two zeros giving 456.40, which is wrong.  It seems
that shortest-match regexps aren't very useful here.  If I remove the ?
in the regexp then it works, but it only removes one layer of zeros at a
time, so e.g. 567.45000 becomes 567.4500.

BR,
Robert Thorpe



reply via email to

[Prev in Thread] Current Thread [Next in Thread]