Answer to CSS Regex Question

I have had a question in my Comments by Rasmus about CSS Regex for obtaining CSS class names. And rather than post it in the comments, I will post it as abn entry just so everyone can see it.

The Regex I gave was
\.[-]?[_a-zA-Z][_a-zA-Z0-9-]*|[^\0-\177]*\\[0-9a-f]{1,6}(\r\n[ \n\r\t\f])?|\\[^\n\r\f0-9a-f]*

I think this is nearly correct and the C# that it is not supposed to work with is:

string css = @"
string patt = @"\.[-]?[_a-zA-Z][_a-zA-Z0-9-]*[^\0-\177]*\\[0-9a-f]{1,6}(\r\n[ \n\r\t\f])?\\[^\n\r\f0-9a-f]*";
string[] arr = Regex.Split(css, patt);

I tried the above code and it worked as Expected, there is an array entry in arr at the index of each class. Therefore each entry in arr contains the text between the class names.

Try Regex.Match if you want to get at the names of the classes. And Check that the | character comes out correctly.

Technorati Tags
[feed], [feed], [feed], [feed], [feed], [feed]

Related Wikipedia Documents
, , ,

My Related Documents

Related Amazon Books
The ZEN of CSS Design: Visual Enlightenment for the Web: / CSS Pocket Reference: / Professional CSS: / Eric Meyer on CSS: /

Related Images From Flickr