@Ian G 的答案更接近一些,但仍然不完整。以下规则不会被它捕获:
background:url("img/test.jpg");
font-size:.8em;
height:auto !important;
line-height:1.2em;
width:calc(100% - 5px);
我对其进行了进一步修改以捕捉这些规则:
([\t\s,;\{])([a-zA-Z\-]+):([\'a-zA-Z\d,\-\:\+\/%#\!\.\"\(\)]+((\s*,\s*|\s+)[\'a-zA-Z\d,\-%#\!\.\"\(\)]+)*([\r\n][\t\s]*)*[;|\}])
我能想到的唯一仍然无法使用的场景是内联数据 URI:
background:url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiA/Pgo8c3ZnIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgd2lkdGg9IjEwMCUiIGhlaWdodD0iMTAwJSIgdmlld0JveD0iMCAwIDEgMSIgcHJlc2VydmVBc3BlY3RSYXRpbz0ibm9uZSI+CiAgPGxpbmVhckdyYWRpZW50IGlkPSJncmFkLXVjZ2ctZ2VuZXJhdGVkIiBncmFkaWVudFVuaXRzPSJ1c2VyU3BhY2VPblVzZSIgeDE9IjAlIiB5MT0iMCUiIHgyPSIwJSIgeTI9IjEwMCUiPgogICAgPHN0b3Agb2Zmc2V0PSIwJSIgc3RvcC1jb2xvcj0iI2ZmZmZmZiIgc3RvcC1vcGFjaXR5PSIxIi8+CiAgICA8c3RvcCBvZmZzZXQ9IjEwMCUiIHN0b3AtY29sb3I9IiNlOGU4ZTgiIHN0b3Atb3BhY2l0eT0iMSIvPgogIDwvbGluZWFyR3JhZGllbnQ+CiAgPHJlY3QgeD0iMCIgeT0iMCIgd2lkdGg9IjEiIGhlaWdodD0iMSIgZmlsbD0idXJsKCNncmFkLXVjZ2ctZ2VuZXJhdGVkKSIgLz4KPC9zdmc+);
;
MIME 类型中的 将其排除在外。但是,修改将捕获稍微错误的 CSS 格式。