I’m trying to filter input selectors (with javascript) from any CSS rules in a stylesheet but can’t write a regex that returns all elements in that rule. I’m fine on the javascript but I’m not sure how to build the right regex.
For example, from the following:
input, #testDiv input, div.test, input[type=radio] {
width: 50px;
}
I need to return input, #testDiv input and input[type=radio] if at all possible (or something close that I can trim down).
Can anyone who knows their regEx’s give me some insight on how to go about it?
For each line of CSS file try this regexp:
Example: http://jsfiddle.net/8DRMz/1/
How it works:
Selector with
inputcan contains different symbols, but new selector always starts with newline, after “,” or after “}”. Also selector always ends with “,” or “{“. So we seeking “input” with any prepended symbols except “,}” and any appended symbols except “,{“.