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
I’m not sure if regex is the way to go, but you can extract the value by using this regex:
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: