用于查找和修改 CSS 文件中数值的工具/脚本?
我只是想遍历并找到单个或一批 CSS 文件中的每个数值,并多次查找两次,然后保存。
对于最简单的方法有什么建议吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用正则表达式可以解决您的问题。例如,在 python 中,您可以执行以下操作:
可以减少此代码的长度,但为了便于阅读,我故意使其不那么紧凑。它的一个缺陷是它会将浮点数压缩为小数点后两位,但如果您确实需要扩展小数位,则可以轻松更改(将
"%s%.2f"
中的数字更改为所需的数字)的地方)。另请注意,此代码可能会更改 CSS 选择器的名称(例如,
#footer-2
将变为#footer-4.00
)。如果您想避免这种情况,则需要调整代码以忽略{...}
之外的文本。Using regular expressions could solve your problem. For example, in python you could do the following:
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{...}
.