首页 新闻 赞助 找找看

急?特殊正则写法!没思路了

0
悬赏园豆:20 [已关闭问题] 关闭于 2012-05-23 16:14

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没有结尾的正则怎写?

jason2013的主页 jason2013 | 小虾三级 | 园豆:1998
提问于:2012-05-22 14:07
< >
分享
所有回答(2)
0

是取name="description"的content的内容么?是的话正则:

<meta\s+name="description"\s+content="(.*?)"\s+/>

使用时要转义

artwl | 园豆:16736 (专家六级) | 2012-05-22 14:37
0

如果是<meta content="xxx" name="description"/>楼上的就取不到了,这个正则稍微有点麻烦,我也暂时写不出。

不过对付这种html解析,.net下有个挺不错的开源,搜一下HtmlAgilityPack。

wdwwtzy | 园豆:114 (初学一级) | 2012-05-23 16:15
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册