string RegexString = "<title>.+?</title>";
string pageStr = "<meta name="description" content="6267 companies listed in 'Agriculture Companies', you can submit free company information here." />";
string resString = "";
Regex reg = new Regex(RegexString, RegexOptions.IgnoreCase);
MatchCollection matches = reg.Matches(pageStr);
foreach (Match match in matches)
{
resString += match.Groups[1].Value;
}
Response.Write(resString+"/Test");
实现功能是:取出description里的之间的值,取<title></title> 比较简单,标签有开始有结尾,这个description没有结尾的正则怎写?
是取name="description"的content的内容么?是的话正则:
<meta\s+name="description"\s+content="(.*?)"\s+/>
使用时要转义
如果是<meta content="xxx" name="description"/>楼上的就取不到了,这个正则稍微有点麻烦,我也暂时写不出。
不过对付这种html解析,.net下有个挺不错的开源,搜一下HtmlAgilityPack。