2012-05-05 22 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

関連する問題