开发者

Parse HTML styles in Regexp

开发者 https://www.devze.com 2023-03-15 01:02 出处:网络
Don\'t know how to create a Regexp开发者_如何转开发 request to check smth like that: p { margin:0

Don't know how to create a Regexp开发者_如何转开发 request to check smth like that:

p {
  margin:0
}
.c0 {
  width:468.0pt;
  background-color:#ffffff;
  padding:72.0pt 72.0pt 72.0pt 72.0pt
}
.c1 {
  direction:ltr
}

It's a part of style in HTML document.So, p - tag, in every style of this tag (c0, c1, etc) there could be different count of properties, Every property has format of PROPERTY_NAME:PROPERTY_VALUE and this properties separated with ;

How to consider all of this things in one Regexp?

Thanks a lot.


Try this:

\.?\w+\s*{\s*(?:(?:(?<name>[^{};]+)\s*:\s*(?<value>[^{};]+));?)+\s*}

Output:

Parse HTML styles in Regexp

Analyzer:

Parse HTML styles in Regexp

0

精彩评论

暂无评论...
验证码 换一张
取 消