0

我试图在一个 css 中获取 {} 中变量不少的所有属性

到目前为止,我的 RegExp 是这样的:

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

示例文本

@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; }

谁能告诉我我该怎么做这个表达?

例子

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

2 回答 2

1

编辑:

试试这个:

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

然后你可以做

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

一个班轮可以是:

( Get-Content .\your.css ) |  % { $_ -replace "({\s*[a-zA-Z-]*:[^@].*\))(.*;)(\s*}$)", '$1$3' } | Set-Content -Path .\yourchanged.css 
于 2012-05-09T11:50:49.333 回答
1

我不知道powershell,但我不知道正则表达式:

([a-zA-Z_-]+:[^}{@]*?;)应该捕获任何不包含@我认为的 css 类属性

( #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
于 2012-05-09T20:11:49.310 回答