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.

Paul Kinlan

Trying to make the web and developers better.

RSS Github Medium