2012-05-05 17 views
1
(?<selector>[^\{\s]+\w+(\s\[^\{\s]+)?)\s?\{(?<style>[^\}]*)\} 

上面幾乎匹配所有情況。有一個正則表達式用於匹配需要調整的CSS

audio:not([controls]) 
{ 
    display:none 
} 

然而,像這樣的東西(與方括號),不正確。

button,input[type="button"],input[type="reset"],input[type="submit"] 
{ 
    cursor:pointer;-webkit-appearance:button 
} 
input[type="search"]::-webkit-search-decoration,input[type="search"]::-webkit-search-cancel-button 
{ 
    -webkit-appearance:none 
} 

這些太...

回答

0

試試這個:

(?<=\}\s*)(?<selector>[^\{\}]+?)(?:\s*\{(?<style>[^\{\}]+)\}) 

說明:

// (?<=\}\s*)(?<selector>[^\{\}]+?)(?:\s*\{(?<style>[^\{\}]+)\}) 
// 
// Options: case insensitive;^and $ match at line breaks 
// 
// Assert that the regex below can be matched, with the match ending at this position (positive lookbehind) «(?<=\}\s*)» 
// Match the character 「}」 literally «\}» 
// Match a single character that is a 「whitespace character」 (spaces, tabs, and line breaks) «\s*» 
//  Between zero and unlimited times, as many times as possible, giving back as needed (greedy) «*» 
// Match the regular expression below and capture its match into backreference with name 「selector」 «(?<selector>[^\{\}]+?)» 
// Match a single character NOT present in the list below «[^\{\}]+?» 
//  Between one and unlimited times, as few times as possible, expanding as needed (lazy) «+?» 
//  A { character «\{» 
//  A } character «\}» 
// Match the regular expression below «(?:\s*\{(?<style>[^\{\}]+)\})» 
// Match a single character that is a 「whitespace character」 (spaces, tabs, and line breaks) «\s*» 
//  Between zero and unlimited times, as many times as possible, giving back as needed (greedy) «*» 
// Match the character 「{」 literally «\{» 
// Match the regular expression below and capture its match into backreference with name 「style」 «(?<style>[^\{\}]+)» 
//  Match a single character NOT present in the list below «[^\{\}]+» 
//   Between one and unlimited times, as many times as possible, giving back as needed (greedy) «+» 
//   A { character «\{» 
//   A } character «\}» 
// Match the character 「}」 literally «\}» 

沒有空白樣式,圖案不匹配!

+0

不錯,謝謝 – Matt