regex match css class name from single string containing multiple classes
Posted
by
effectica
on Stack Overflow
See other posts from Stack Overflow
or by effectica
Published on 2012-09-12T15:36:09Z
Indexed on
2012/09/12
15:38 UTC
Read the original article
Hit count: 203
I have a long string that contains multiple css classes. With regex I would like to match every class name as I then need to replace these class names like so:
<span>CLASSNAME</span>
I have tried for hours to come up with a solution and I think I am close however for certain class names I am not able to exclude closing curly brackets from the match.
Here is a sample string I have been carrying out testing on:
#main .items-Outer p{ font-family:Verdana; color: #000000; font-size: 50px; font-weight: bold; }#footer .footer-inner p.intro{ font-family:Arial; color: #444444; font-size: 30; font-weight: normal; }.genericTxt{ font-family:Courier; color: #444444; font-size: 30; font-weight: normal; }
And here is the the regex I came up with so far:
((^(?:.+?)(?:[^{]*))|((?:\})(?:.+?)(?:[^{]*)))
Please look at the screenshot I am attaching as it will show more clearly the matches I get. My problem is that I would obviously like to exclude curly brackets from any match.
© Stack Overflow or respective owner