I am trying to write a CSS minifier script for fun and I now want to create a function that removes any unnecessary 0.x
with only .x
. So for example this string:
attribute:0.12% 10.123% 0.1%
Should turn into:
attribute:.12% 10.123% .1%
I tried to use a simple replace like this: .replaceAll(':0.', ':.')
but this doesn't work for the case when the number stands alone like the 0.1%
does in my example.
I am not very good with regular expressions but I guess that is what I need. So basically I want to find all numbers that match the format 0.
but DON'T have a number immediately to the left of them (like in the case 10.123%
) and replace it with .
.