What is the REGEX of a CSS selector

前端 未结 9 2009
你的背包
你的背包 2021-02-02 12:27

I\'d like to parce a CSS file and add before every CSS selector another selector.

From:

p{margin:0 0 10px;}
.lead{margin-bottom:20px;font-size:21px;font-         


        
9条回答
  •  遥遥无期
    2021-02-02 12:58

    Here's the solution I used for a similar problem. I wanted to remove all css rules that started with @. For this I used the following regex:

    @\s*.*\s*\{((?!\n\})[\s\S])+\n\}

    It makes the assumption that the rule ends on a new line. That way it can sort of handle nested css rules.

提交回复
热议问题