What is the REGEX of a CSS selector

前端 未结 9 2039
你的背包
你的背包 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 13:10

    There isn't one. CSS selectors are not an example of a "Regular Language" and so cannot be parsed by a Regular Expression. You will need to build your own parser based on the CSS grammar specification: http://www.w3.org/TR/css3-syntax/#detailed-grammar

    CSS is described as an LL(1) grammar, so you're probably better off using a tool like Yacc to generate your parser for you.

提交回复
热议问题