本帖最后由 swb1203 于 2010-07-13 19:15:21 编辑

解决方案 »

  1.   

    (?is)comInformation.asp\?id=(?<id>\d+)[^>]*>(?<position>[^<>]+).+?companyJob.asp\?fzy=(?<company_id>\d+)[^>]*>(?<company>[^<>]+)分别:
    id
    position
    company_id
    company
    四个分组的值就是你要的
      

  2.   

                string test = @"<dl>
    <!-- style=""color:#0066ff; text-decoration:none;""--> <dt><h3><a href=""http://www.shr.com/newcreate/comInformation.asp?id=70396"" target=""_blank"">
    Asp程序员 </a><!--软件工程师--></h3>   
    | 工作地点:河南省郑州市| 工作经验:
    2年 | 学历:大专   
      | 发布时间:2010-7-12 </dt>
    <dd><h4><a href=""http://www.shr.com/companyJob.asp?fzy=46501"" target=""_blank"">郑州XX实业有限公司</a>&nbsp;<img src='http://www.shr.com/newcreate/images/vip1.gif' width='31' height='13' />&nbsp;<a href='http://www.baidu.com/baidu?word=%D6%A3%D6%DD%C9%CF%C9%C6%C8%F4%CB%AE%CA%B5%D2%B5%D3%D0%CF%DE%B9%AB%CB%BE' target='_blank'><font color='#FF0000'</dd>
    ";
                Match m = Regex.Match(test, @"(?is)comInformation.asp\?id=(?<id>\d+)[^>]*>(?<position>[^<>]+).+?companyJob.asp\?fzy=(?<company_id>\d+)[^>]*>(?<company>[^<>]+)");
                if (m.Success)
                {
                    Console.WriteLine("职员编号=" + m.Groups["id"].Value);
                    Console.WriteLine("职位=" + m.Groups["position"].Value);
                    Console.WriteLine("公司编号=" + m.Groups["company_id"].Value);
                    Console.WriteLine("公司名=" + m.Groups["company"].Value);
                }
      

  3.   

    position  的值并没有得到啊
      

  4.   

    怎么可能嘛。你测试没。
    你的职位这里有换行,所以到第二行显示了。
    我当时就怕你不会,但想想。不至于给了例子还要手把手的把细节都处理掉,因为例子就是例子,你最终的应用才需要处理细节。既然你不愿意思考,贴出来去掉回车换行的吧。诶。我不信你真的测试过,至少你没有debug的看每个匹配结果是什么。        private static void TestRegex08()
            {
                string test = @"<dl>
    <!-- style=""color:#0066ff; text-decoration:none;""--> <dt><h3><a href=""http://www.shr.com/newcreate/comInformation.asp?id=70396"" target=""_blank"">
    Asp程序员 </a><!--软件工程师--></h3>   
    | 工作地点:河南省郑州市| 工作经验:
    2年 | 学历:大专   
      | 发布时间:2010-7-12 </dt>
    <dd><h4><a href=""http://www.shr.com/companyJob.asp?fzy=46501"" target=""_blank"">郑州XX实业有限公司</a>&nbsp;<img src='http://www.shr.com/newcreate/images/vip1.gif' width='31' height='13' />&nbsp;<a href='http://www.baidu.com/baidu?word=%D6%A3%D6%DD%C9%CF%C9%C6%C8%F4%CB%AE%CA%B5%D2%B5%D3%D0%CF%DE%B9%AB%CB%BE' target='_blank'><font color='#FF0000'</dd>
    ";
                Match m = Regex.Match(test, @"(?is)comInformation.asp\?id=(?<id>\d+)[^>]*>(?<position>[^<>]+).+?companyJob.asp\?fzy=(?<company_id>\d+)[^>]*>(?<company>[^<>]+)");
                if (m.Success)
                {
                    Console.WriteLine("职员编号=" + m.Groups["id"].Value.Trim("\r\n".ToCharArray()));
                    Console.WriteLine("职位=" + m.Groups["position"].Value.Trim("\r\n".ToCharArray()));
                    Console.WriteLine("公司编号=" + m.Groups["company_id"].Value.Trim("\r\n".ToCharArray()));
                    Console.WriteLine("公司名=" + m.Groups["company"].Value.Trim("\r\n".ToCharArray()));
                }
            }