What is the REGEX of a CSS selector
Posted
by
user421563
on Stack Overflow
See other posts from Stack Overflow
or by user421563
Published on 2012-09-25T03:33:17Z
Indexed on
2012/09/25
3:37 UTC
Read the original article
Hit count: 165
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
© Stack Overflow or respective owner