写了半天了,总是不行...
下班之前要搞定,急哇..第一个:
<a class="underline" href="http://www.test.com">
<h2>标题</h2>
</a>第二个:
<a href="http://www.test.com" class="offerHeading" target="_blank">
标题
</a>第三个:
<a href="http://www.test.cp," 
onclick="show()" title="test" class="company_name">
标题
</a>主要是写三个正则表达式,获取出以上三个链接中的 href属性和 标题..
求高人帮忙哇...

解决方案 »

  1.   

    string yourstr=@"<a class=""underline"" href=""http://www.test.com""> 
    <h2>标题 </h2> 
    </a> ";
    MatchCollection mc = Regex.Matches(yourstr, @"(?is)<a\s+[^>]*href=""(?<url>[^""]*)"">\s*<h2>(?<title>.*)</h2>", RegexOptions.None);
    foreach (Match ma in mc)

    Console.WriteLine(ma.Groups["url"].Value);
    Console.WriteLine(ma.Groups["title"].Value);
    }
    /*
    http://www.test.com
    标题 
    */
      

  2.   

    <(a|A)\w*href=\"(\w*)\" \w*>
      

  3.   

    //第二个,第三个 (?is)<a\s+[^>]*href=""(?<url>[^""]*)""[^>]*>\s*(?<title>.*)</a>string yourstr=@"<a href=""http://www.test.com"" class=""offerHeading"" target=""_blank""> 
    标题 
    </a> ";
    MatchCollection mc = Regex.Matches(yourstr, @"(?is)<a\s+[^>]*href=""(?<url>[^""]*)""[^>]*>\s*(?<title>.*)</a>", RegexOptions.None);
    foreach (Match ma in mc)

    Console.WriteLine(ma.Groups["url"].Value);
    Console.WriteLine(ma.Groups["title"].Value);
    }
    /*
    http://www.test.com
    标题 
    */
      

  4.   

     string str="";
                string strPattern=@"a[\s]+href=(?<Link>[^\s>]+)[^>]*>(?<Text>[^<]*)</a>";
                MatchCollection Matches=Regex.Matches(webDocContent,strPattern,RegexOptions.IgnoreCase|RegexOptions.Compiled);
                foreach(Match NextMatch in Matches)
                {
                    string URL=NextMatch.Groups["Link"].Value.ToString().Trim();
                    string URLText=NextMatch.Groups["Text"].Value.ToString().Trim();
                    Response.Write(URL);
                    Response.Write(URLText);
                }
      

  5.   

    (?is)<a\s+[^>]*href="(?<url>[^"]*)"[^>]*>\s*<h2>(?<title>[^<]*)</h2>\s*</a>
    (?is)<a\s+[^>]*href="(?<url>[^"]*)"[^>]*>\s*(?<title>[^<]*)\s*</a>
      

  6.   


    第二个和第三个不能写成通用的哦,
    第二个必须考虑 class="offerHeading"
    第三个必须考虑 class="company_name"
      

  7.   


    第二个和第三个不能写成通用的哦,
    第二个必须考虑 class="offerHeading"
    第三个必须考虑 class="company_name"
      

  8.   

    //1
    (?is)<a\s+[^>]*href="(?<url>[^"]*)"[^>]*>\s*<h2>(?<title>[^<]*)</h2>\s*</a>
    //2
    (?is)<a\s+[^>]*href="(?<url>[^"]*)"\s*class="offerHeading"[^>]*>\s*(?<title>[^<]*)\s*</a>
    //3
    (?is)<a\s+[^>]*href="(?<url>[^"]*)"[^>]*class="company_name"[^>]*>\s*(?<title>[^<]*)\s*</a>