Regular expression and CSS
-
Hi everyone, i need a regular expression that can extract the name and content section from each class in a css file... .Data1{color:#000000} .Data2{ color:#111111 } .Data3{ color:#222222 } the regexp should extract : .Data1 => color:#000000 .Data2 => color:#111111 .Data3 => color:#222222 Without the { or } chars Ive tried but nothing seems to work....im only be able to parse .Data1{color:#000000} using this expression (\.(.+){(.+)}) Thanks in advance.
-
Hi everyone, i need a regular expression that can extract the name and content section from each class in a css file... .Data1{color:#000000} .Data2{ color:#111111 } .Data3{ color:#222222 } the regexp should extract : .Data1 => color:#000000 .Data2 => color:#111111 .Data3 => color:#222222 Without the { or } chars Ive tried but nothing seems to work....im only be able to parse .Data1{color:#000000} using this expression (\.(.+){(.+)}) Thanks in advance.
Allow for line breaks inside the brackets. Also you need to make your quantifiers non-greedy, or you will be cathing everything in the first match. (\.(.+?){\s*(.+?)\s*}) If the content contains line breaks, a period doesn't match that. (\.(.+?){\s*([\w\W]+?)\s*})
--- single minded; short sighted; long gone;
-
Allow for line breaks inside the brackets. Also you need to make your quantifiers non-greedy, or you will be cathing everything in the first match. (\.(.+?){\s*(.+?)\s*}) If the content contains line breaks, a period doesn't match that. (\.(.+?){\s*([\w\W]+?)\s*})
--- single minded; short sighted; long gone;
I found this article, it might be useful http://www.codeproject.com/csharp/CSSParser.asp
-
I found this article, it might be useful http://www.codeproject.com/csharp/CSSParser.asp
-
Nice of you to add it to the thread, so that other might benefit. :)
--- single minded; short sighted; long gone;