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

以上匹配几乎所有情况。

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
}

这些也...

4

1 回答 1

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 «\}»

没有空白样式,图案不匹配!

于 2012-05-05T07:42:53.627 回答