I want to use regular expression to clean-up some CSS files.

I used a Friebug add-on, CSS Usage, to analyse some CSS from a jquery demo. Exporting the files, this add-on places 'UNUSED' at the front of a declaration and rule. Below is a sample of the output.

html #demo-config-menu li a:link,
UNUSED* html #demo-config-menu li a:visited {
 padding:1px 8px 2px;

UNUSED#demo-config-menu li a:active,
#demo-config-menu li a:hover {

UNUSED#demo-config-menu h4 {
 font-size:13px; color:#666; font-weight:normal; border:0; padding-left:18px;

New to regular expressions, I have tried in vain to come up with search parameters for what I want.

  1. a way to search compound selectors for instances of UNUSED and the selector that follows, be it the first or second selector within a CSS rule (as in first two code samples);
  2. search for a complete declaration and rule as in the last code example

I have looked at tutorial on youtube and other sources. I can have success with anything up to and before ' {' but can not the search parameters to work beyond that.

Anyone have suggestions?

Recommended Answers

All 2 Replies

Can you show what the output should be? And what tool are you using to for the replacements?

Something like /UNUSED([^,{]+)/ could work.

By and large, I don't want replacements. I merely wish to remove the selectors prefaced with UNUSED and for the declarations that are singular, strip the entire declaration and rule from the CSS.

So, based on the code examples provided, I need search paramets that will go something like ", UNUSED [everything to next]," "UNUSED [everything to next]," "UNUSED [everything to space {] but leave the space {" "UNUSED [everything to ]}\n"
I know those are not appropriate syntax. Just My pseudo-code.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.