Tip #831: regexp to strip redundant zeroes in decimal fractions
tip karma |
Rating 9/3, Viewed by 958
|
Read and edit this tip on the
Vim tip wiki.
The wiki may have a more recent version of this tip.
created: |
|
December 8, 2004 10:01 |
|
complexity: |
|
basic |
author: |
|
Andrew Nikitin |
|
as of Vim: |
|
6.0 |
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.
<< Using netbeans 4 and vim for java |
Remembering previous deletes/yanks >>
Additional Notes
[email protected],
January 4, 2005 6:36
|
Can't you just use Regexp memory here?
|
Anonymous,
April 28, 2005 13:12
|
This is a great tip, but there's a little typo. There should only be one closing brace not two. }
Thanks!
|
|