how to use regular expression to get value from string
c#, regex
Solution
I'm not sure if regex is the way to go, but you can extract the value by using this regex:
h2 \\{color: (#(\\d|[a-f]){6};)}
Getting the first Group from this will get you the value that belongs to the color of the h2.
Edit
This piece of code should get it:
String regex = "h2 \\{color: (#(\\d|[a-f]){6};)}";
String input = "<meta http-equiv=\"Content-Type\" content=\"text/html;\" charset=\"utf-8\"><style type=\"text/css\">body {font-family: Helvetica, arial, sans-serif;font-size: 16px;}h2 {color: #e2703b;}.newsimage{margin-bottom:10px;}.date{text-align:right;font-size:35px;}</style>";
MatchCollection coll = Regex.Matches(input, regex);
String result = coll[0].Groups[1].Value;
Problem
I have this string text: ``` <meta http-equiv="Content-Type" content="text/html;" charset="utf-8"> <style type="text/css"> body { font-family: Helvetica, arial, sans-serif; font-size: 16px; } h2 { color: #e2703b; }.newsimage{ margin-bottom:10px; }.date{ text-align:right;font-size:35px; } </style> ``` Newlines and idents are added for clarity, real string does not have it How can I get value of `h2` color? In this case it should be - `#e2703b;` I don't know how to use regular expressions in this case. Update If I try this way: ``` Match match = Regex.Match(cssSettings, @"h2 {color: (#[\d|[a-f]]{6};)"); if (match.Success) { string key = match.Groups[1].Value; } ``` it doesn't work at all