Tip: #831 - Regexp to strip redundant zeroes in decimal fractions
Created: December 8, 2004 10:01 Complexity: basic Author: Andrew Nikitin Version: 6.0 Karma: 9/3 Imported from: Tip#831
Vim command
%s/\(\.\d\+\)\@<=0\+\>//g
will strip all trailing (meaningless) zeroes in decimal fractions. Some of my data files lost 50% fat after this procedure and also became much more human readable.
I guess "correct"regular expression should be
\(\.\d\{-1,\)\@<=0\+\>
(since the intention is to preserve just one zero that comes right after decimal point), but for some reason original expression works as well.
I guess this serves as another example of how \@<= regexp token makes things so much easier.
}}
Comments
Can't you just use Regexp memory here?
Anony--AT--mouse.com , January 4, 2005 6:36
This is a great tip, but there's a little typo. There should only be one closing brace not two. } Thanks!
Anonymous , April 28, 2005 13:12