开发者

Grab every css class name declared between curly braces using regex

开发者 https://www.devze.com 2023-01-07 08:58 出处:网络
Hi Im trying to write a simple CSS parsing script in PHP that enables me to put previously declared classes within a css rule, i.e. the Mixins functionality of less and Sassy.

Hi Im trying to write a simple CSS parsing script in PHP that enables me to put previously declared classes within a css rule, i.e. the Mixins functionality of less and Sassy.

This regex only grabs the last css class name within the curly braces:

{.+(\.\w+).+}

For example, only .foo will be matched in the below css rule:

.login_form_container  { .gradient .rounded_corners width:431px;开发者_如何学编程 height:282px; margin:250px auto 0; .foo }

Thanks!


Why don't you just use lessphp?


Ok, try this one:

{(?:[^\.]*(\.\w+))+[^\.]*}

0

精彩评论

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

关注公众号