0

Im trying to get in a css all the atributes that aren't less variables inside the { }

So far my RegExp is like this:

\s*[a-zA-Z-]*:[^@].*?;

Example Text

@footerBackground: @Color1;
@footerText: @Color3;
footer          { background:@footerBackground url(images/bg.transp.fabric-45degreee_fabric.png) repeat; box-shadow:0 -1px 3px rgba(0, 0, 0, 0.25), inset 0 1px 0 rgba(0, 0, 0, 0.1); bottom:0; color:@footerText; position:absolute; width:100%; }
footer a        { color:@footerLink !important; }
footer a:hover  { color:darken(@footerLink, 15%) !important; text-decoration:none; }
#footer-widgets { border-bottom:1px darken(@footerBackground,10%) dotted; padding:20px 0; }

Can anyone tell me how can i do this expression?

example

discart if have @ - color:darken(@tuningfooterLink, 15%) !important;
get - text-decoration:none;
0

2 Answers 2

1

I dont know powershell, but ill have a go at the regex:

([a-zA-Z_-]+:[^}{@]*?;) should capture any css class attribute not containing @ I think

( #group1
  [a-zA-Z_-] #Character class matching a-z, A-Z, _ and -
  + #match character class atleast once (applies to [a-zA-Z_-])
  : #match a :
  [^}{@] #Character class matchting all characters except {, }. and @
  + #match character class atleast once (applies to [^}{@])
  ? #dont be a greedy matcher (applies to +)
  ; #match a ; the closing char for any valid CSS rule
) #close group1
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for the reply, it work great with this expression but is getting also the initialization of the variables less, i update my example above, can you have a look?
hmm thats maybe a powershell issue, seems to work fine in ruby, rubular.com/r/YRG82Fk2X6
1

Edit:

Try this:

$a = Get-Content .\your.css
$b = $a | % { $_ -replace "({\s*[a-zA-Z-]*:[^@].*\))(.*;)(\s*}$)", '$1$3' }

Then you can do

Set-Content -Path .\yourchanged.css -Value $b.

One liner can be:

( Get-Content .\your.css ) |  % { $_ -replace "({\s*[a-zA-Z-]*:[^@].*\))(.*;)(\s*}$)", '$1$3' } | Set-Content -Path .\yourchanged.css 

4 Comments

Thanks for the reply, I'm using this gskinner.com/RegExr to test the expressions but with my expression i dont know how to discart ( color:darken(@tuningfooterLink, 15%) !important; )
I'm trying to remove all atributes inside { } that don't have variables (represented by @variable) . In footer a:hover { color:darken(@footerLink, 15%) !important; text-decoration:none; } i want to remove for example "text-decoration:none;"
It's almost there, i will see what i can do more with your expression
Hope can help you to reach your goal!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.