本文介绍了正则表达式匹配任何“UNUSED” CSS中的规则(类,id等)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个巨大的CSS文件,我想修剪下来只使用CSS规则。

I have a huge CSS file which I want to trim down to only used css rules.

我使用。它为每个未使用的规则添加一个UNUSED标签。现在我想摆脱这些。

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代码看起来像这样:

The CSS code looks like this:

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.

我的正则表达式为:

\{([^}]+)\}


$ b b

如何修改表达式以选择从UNUSED到结束大括号的任何内容?但是,只有当事情从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's regex is a bit more complex but it's better and safer. Take a look at it.

这篇关于正则表达式匹配任何“UNUSED” CSS中的规则(类,id等)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-14 22:15