string metaKey = String.Empty, metaValue = String.Empty;
foreach (Match metamatch in Regex.Matches (htmlData,
@"<meta\s*(?:(?:\b(\w|-)+\b\s*(?:=\s*(?:""[^""]*""|'" +
@"[^']*'|[^""'<> ]+)\s*)?)*)/?\s*>",
RegexOptions.IgnoreCase|RegexOptions.ExplicitCapture)) {
metaKey = String.Empty;
metaValue = String.Empty;
// Loop through the attribute/value pairs inside the tag
foreach (Match submetamatch in Regex.Matches(metamatch.Value.ToString(),
@"(?<name>\b(\w|-)+\b)\s*=\s*(""(?<value>" +
@"[^""]*)""|'(?<value>[^']*)'|(?<value>[^""'<> ]+)\s*)+",
RegexOptions.IgnoreCase|RegexOptions.ExplicitCapture)) {
if ("http-equiv" == submetamatch.Groups[1].ToString().ToLower() ) {
metaKey = submetamatch.Groups[2].ToString();
}
if ( ("name" == submetamatch.Groups[1].ToString().ToLower() )
&& (metaKey == String.Empty) ) {
// if already set, HTTP-EQUIV overrides NAME
metaKey = submetamatch.Groups[2].ToString();
}
if ("content" == submetamatch.Groups[1].ToString().ToLower() ) {
metaValue = submetamatch.Groups[2].ToString();
}
}
switch (metaKey.ToLower()) {
case "description":
htmldoc.Description = metaValue;
break;
case "keywords":
case "keyword":
htmldoc.Keywords = metaValue;
break;
case "robots":
case "robot":
htmldoc.SetRobotDirective (metaValue);
break;
}
}
