什么是CSS选择器的REGEX [英] What is the REGEX of a CSS selector

查看:115
本文介绍了什么是CSS选择器的REGEX的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要解析CSS文件,并在每个CSS选择器之前添加另一个选择器。



From:

  p {margin:0 0 10px;} 
.lead {margin-bottom:20px; font-size:21px; font-weight:200; line-height: 30px;}

我想:

  .mySelector p {margin:0 0 10px;} 
.mySelector .lead {margin-bottom:20px; font-size:21px; font-weight:200; line -height:30px;}

但是我的CSS文件非常复杂(实际上是bootstrap css文件),所以正则表达式应该匹配所有的CSS选择器。



现在我有了这个regex:

 ([^ \r\\\
,{};] +)(,| {)

,您可以在此查看 http://regexr.com?328ps
的结果,但是您可以看到有很多不匹配的匹配



例如:

  text-shadow:0 -1px 0 rgba(0,

匹配正不应



有人有解决方案吗?



THX



我使用一个LESS编辑器例如: http://lesstester.com/



并简单地嵌入我的整个css文件:
.mySelector {your css here}


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-weight:200;line-height:30px;}

I'd like:

.mySelector p{margin:0 0 10px;}
.mySelector .lead{margin-bottom:20px;font-size:21px;font-weight:200;line-height:30px;}

But my CSS file is really complex (in fact it is the bootstrap css file) so the regex should match all CSS selectors.

For now I have this regex:

([^\r\n,{};]+)(,|{)

and you can see the result here http://regexr.com?328ps but as you can see there are a lot of matches that shouldn't match

for example:

text-shadow:0 -1px 0 rgba(0,

matchs positive but it shouldn't

Does someone have a solution ?

THX

解决方案

So finally I've found a way better way to do it.

I use a LESS editor (eg: http://lesstester.com/)

and simply nest my whole css file: .mySelector{ your css here }

这篇关于什么是CSS选择器的REGEX的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆