I simply want to go through and find every numerical value in a single, or batch of, CSS files and multiple times two, then save.
Any suggestions for the easiest way to do this?
I simply want to go through and find every numerical value in a single, or batch of, CSS files and multiple times two, then save.
Any suggestions for the easiest way to do this?
Using regular expressions could solve your problem. For example, in python you could do the following:
import re
input = "#content {width:100px;height:20.5%;font-size:150.25%;margin-left:-20px;padding:2 0 -20 14.33333;}"
regex = re.compile("-?[.0-9]+")
scaled_numbers = [float(n)*2 for n in re.findall(regex, input)]
split_text = re.split(regex, input)
output = ''
for i in range(len(scaled_numbers)):
output += "%s%.2f" % (split_text[i], scaled_numbers[i])
output += split_text[-1]
This code could be reduced in length, but I've deliberately left it less compact for readability. One flaw with it is that it contracts floats to only 2 decimal places, but that can be easily changed if you really need extended decimals (change the number in "%s%.2f"
to the desired number of places).
Note also that this code could change the names of CSS selectors (for example, #footer-2
would become #footer-4.00
). If you wanted to avoid that, you'll need to adjust the code to ignore text outside of {...}
.