问题描述
我有一个很大的CSS文件,我想将其缩小为仅使用的CSS规则.
I have a huge CSS file which I want to trim down to only used css rules.
我是通过使用 CSS用法加载项用于Firebug.它将为每个未使用的规则添加一个未使用"标签.现在我要摆脱这些.
I did this by using CSS Usage Add-on for Firebug. It adds an "UNUSED" label to every rule not being used. Now I want to get rid of these.
CSS代码如下:
body {
line-height: 1;
text-align: left;
}
UNUSED.multiple-list {
font-weight: bold;
line-height: 1.4;
list-style: disc;
margin-left: 20px
}
UNUSEDmenu, UNUSEDol, ul {
list-style: none
}
UNUSEDblockquote, UNUSEDq {
quotes: none
}
我试图使用RegExr在线服务找到自己的Regex,但是我只能选择花括号之间的部分.
I tried to find my own Regex using RegExr online service but I was only able to select the part in between the curly braces.
到目前为止,我的正则表达式:
My Regular expression so far:
\{([^}]+)\}
如何修改表达式以选择从未使用"到右花括号的任何内容?但仅当事情以"UNUSED"开头时?所有其他规则都不应标记.
How can I modify the expression to select anything from "UNUSED" to the closing curly brace? But only if things start with "UNUSED"? All other rules should not be marked.
推荐答案
此正则表达式将匹配任何UNUSED属性: UNUSED.* \ {[^}] * \} | UNUSED.* [}] *
正则表达式的第一部分与任何包含块的UNUSED属性匹配,而正则表达式的第二部分(在 |
之后)与任何不包含块的UNUSED属性匹配-因此您被完全覆盖.它将匹配类,id,块,单行-每个UNUSED属性.
The first part of the regex matches any UNUSED attribute that includes a block, and the second part of the regex (after the |
) matches any UNUSED attribute that does not include a block - so you're totally covered.It will match classes, id's, blocks, single lines - every UNUSED attribute.
* jdlx的正则表达式稍微复杂一些,但更好,更安全.看看吧.
* jdlx's regex is a bit more complex but it's better and safer. Take a look at it.
这篇关于正则表达式以匹配任何&"UNUSED&"CSS中的规则(类,ID等)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!