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 = @”.class1{color:pink;}.class2{color:blue;}”;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.


This content originally appeared on Modern Web Development with Chrome and was authored by Paul Kinlan

<p>I have had a question in my <a href="http://www.kinlan.co.uk/2006/02/regex-to-get-class-names-from-css-20.html#c113916701172912826">Comments by Rasmus</a> 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.<p />The Regex I gave was.[-]?[_a-zA-Z][_a-zA-Z0-9-]<em>|[^\0-\177]</em>\[0-9a-f]{1,6}(\r\n[ \n\r\t\f])?|\[^\n\r\f0-9a-f]<em><p />I think this is nearly correct and the C# that it is not supposed to work with is:<p />string css = @".class1{color:pink;}.class2{color:blue;}";string patt = @".[-]?[_a-zA-Z][_a-zA-Z0-9-]</em>[^\0-\177]<em>\[0-9a-f]{1,6}(\r\n[ \n\r\t\f])?\[^\n\r\f0-9a-f]</em>";string[] arr = Regex.Split(css, patt);}<p />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.<p />Try Regex.Match if you want to get at the names of the classes. And Check that the | character comes out correctly.<p /></p>


This content originally appeared on Modern Web Development with Chrome and was authored by Paul Kinlan


Print Share Comment Cite Upload Translate Updates
APA

Paul Kinlan | Sciencx (2006-02-06T00:00:00+00:00) Answer to CSS Regex Question. Retrieved from https://www.scien.cx/2006/02/06/answer-to-css-regex-question/

MLA
" » Answer to CSS Regex Question." Paul Kinlan | Sciencx - Monday February 6, 2006, https://www.scien.cx/2006/02/06/answer-to-css-regex-question/
HARVARD
Paul Kinlan | Sciencx Monday February 6, 2006 » Answer to CSS Regex Question., viewed ,<https://www.scien.cx/2006/02/06/answer-to-css-regex-question/>
VANCOUVER
Paul Kinlan | Sciencx - » Answer to CSS Regex Question. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2006/02/06/answer-to-css-regex-question/
CHICAGO
" » Answer to CSS Regex Question." Paul Kinlan | Sciencx - Accessed . https://www.scien.cx/2006/02/06/answer-to-css-regex-question/
IEEE
" » Answer to CSS Regex Question." Paul Kinlan | Sciencx [Online]. Available: https://www.scien.cx/2006/02/06/answer-to-css-regex-question/. [Accessed: ]
rf:citation
» Answer to CSS Regex Question | Paul Kinlan | Sciencx | https://www.scien.cx/2006/02/06/answer-to-css-regex-question/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.