本帖最后由 l6463892y 于 2013-08-24 13:24:44 编辑

解决方案 »

  1.   

    Match m = Regex.Match("匹配文本", "正則表達式"); 
      

  2.   

    using System.Text.RegularExpressions;
      

  3.   

    表达式里又是*又是?的
                //网页操作对象,我用来获取网页源码
                HTML html = new HTML();            //对博客园每日排行数据进行采集
                string htmlcode = html.GetHTML("http://www.cnblogs.com/TopPosts.aspx","utf-8");            //提取博客园排行文章信息的正则表达式
                Regex regexarticles = new Regex(".+· <a\\s+id=\".+\" href=\"(?<url>.+)\"\\s+target=\"_blank\">(?<title>.+)</a> <span\\s+class=\".+\">\\(阅读:(?<views>\\d+)\\).*\\(评论:(?<reply>\\d+)\\).*\\((?<time>.+)\\)</span>\\s*</td>\\s*<td\\s+height=\"\\d+\">\\s+<a\\s+id=\".+\" href=\"(?<blog>.+)\">(?<author>.+)</a>");            //所有匹配表达式的内容
                MatchCollection marticles = regexarticles.Matches(htmlcode);               /**////遍历匹配内容
                foreach (Match m in marticles)
                {
                    Entity.Article test = new Entity.Article();
                    test.Category = "博客园热门文章";           //设置分类
                    test.Title = m.Groups["title"].Value;       //设置标题
                    test.Url = m.Groups["url"].Value;           //设置连接
                    test.Views = int.Parse(m.Groups["views"].Value);    //设置浏览次数
                    test.Replys = int.Parse(m.Groups["reply"].Value);  //设置评论次数
                    test.Datatime = m.Groups["time"].Value;             //设置发布时间
                    test.Author = m.Groups["author"].Value;             //设置作者
                    test.Site = m.Groups["blog"].Value;                 //设置文章出处
                    list.Add(test);
                }
          MatchCollection marticles = regexarticles.Matches(htmlcode);
      

  4.   

    class="re\?sul\\t" id="[\s\S]*?target="_blank"[\s\S]*?>([\s\S]*?)</a></h3><div class="c-abstract">([\s\S]*?)</div>" 取Groups[1].Value就是红色部分得值
    取Groups[2].Value就是蓝色部分得值