求一个正则表达式,这次难度有所提升,需要去掉中间一些超链接。
解析如下内容:
<td id="colE3E">Windows XP Service Pack 1</td><td id="colE6E">Windows XP Service Pack 2</td><td id="colECF">Windows Server 2003</td><td id="colEFF" style="border-right: 1px solid rgb(204, 204, 204);">Windows Server 2003 Service Pack 1</td></tr></thead><tbody><tr class="record" valign="top"><td><p class="lastInCell">用户配置文件特权提升漏洞 - <a href="http://www.cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2006-3443" target="_blank">CVE-2006-3443</a></p></td><td><p class="lastInCell">特权提升</p></td><td><p class="lastInCell">重要</p></td><td><p class="lastInCell">低</p></td><td><p class="lastInCell">低</p></td><td><p class="lastInCell">低</p></td><td style="border-right: 1px solid rgb(204, 204, 204);"><p class="lastInCell">低</p></td></tr><tr class="evenRecord" valign="top"><td><p class="lastInCell">未处理的异常漏洞 - <a href="http://www.cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2006-3648" target="_blank">CVE-2006-3648</a></p></td>要获取的内容为:
用户配置文件特权提升漏洞 - CVE-2006-3443
未处理的异常漏洞 - CVE-2006-3648多谢多谢!

解决方案 »

  1.   

    试试:string tmp = "<td id=\"colE3E\">Windows XP Service Pack 1</td><td id=\"colE6E\">Windows XP Service Pack 2</td><td id=\"colECF\">Windows Server 2003</td><td id=\"colEFF\" style=\"border-right: 1px solid rgb(204, 204, 204);\">Windows Server 2003 Service Pack 1</td></tr></thead><tbody><tr class=\"record\" valign=\"top\"><td><p class=\"lastInCell\">用户配置文件特权提升漏洞 - <a href=\"http://www.cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2006-3443\" target=\"_blank\">CVE-2006-3443</a></p></td><td><p class=\"lastInCell\">特权提升</p></td><td><p class=\"lastInCell\">重要</p></td><td><p class=\"lastInCell\">低</p></td><td><p class=\"lastInCell\">低</p></td><td><p class=\"lastInCell\">低</p></td><td style=\"border-right: 1px solid rgb(204, 204, 204);\"><p class=\"lastInCell\">低</p></td></tr><tr class=\"evenRecord\" valign=\"top\"><td><p class=\"lastInCell\">未处理的异常漏洞 - <a href=\"http://www.cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2006-3648\" target=\"_blank\">CVE-2006-3648</a></p></td>";
                 
    tmp = System.Text.RegularExpressions.Regex.Replace(tmp,"<(.|\n)+?>","");
      

  2.   

    谢谢楼上的老兄,但你提供的这个不行啊,这个只是把html标识去掉了,返回的内容是
    "Windows XP Service Pack 1Windows XP Service Pack 2Windows Server 2003Windows Server 2003 Service Pack 1用户配置文件特权提升漏洞 - CVE-2006-3443特权提升重要低低低低未处理的异常漏洞 - CVE-2006-3648"跟我想要的不相同。我想要的应该是有两条记录,分别为:
    用户配置文件特权提升漏洞 - CVE-2006-3443
    未处理的异常漏洞 - CVE-2006-3648
      

  3.   

    <p class="lastInCell">(.*?) - <a href=.*?>(.*?)</a></p></td><td><p class=.*?>.*?<tr.*?><td><p class=.*?>(.*?) - <a href=.*?>(.*?)</a>
    得出1234
      

  4.   

    不用正则行不行?
            Dim str1 As String = webtext
            Dim str2() As String
            str2 = str1.Split("<p class=""lastInCell"">")
            For i As Integer = 0 To UBound(str2) - 1
                Debug.Print(Strings.Left(str2(i), InStr(str2(i), "<a href=") - 1))
            Next
      

  5.   

    to wthorse()
    我先试试,在C#中,<p class="lastInCell">(.*?) - <a href=.*?>(.*?)</a></p></td><td><p class=.*?>.*?<tr.*?><td><p class=.*?>(.*?) - <a href=.*?>(.*?)</a>,这样的正则应该如何获取其中的值呢?我C#是初学,谢谢啊!to BeRush(艾威)
    能举个例子吗?没用过document对象,谢谢!to bejon(阿牛[千分散尽还复来])
    有C#版本的吗,呵呵:)
    不用正则也可以,但这个html代码中可能不只一处<p class=""lastInCell"">,别的地方也有<p class=""lastInCell"">的。谢谢!
      

  6.   


    to wthorse()
    你的方法可以获取这个示例中的内容:)
    但如果html中包含的信息不固定,有可能是1条、2条、3条,或者更多条数据时应该怎么处理?
    谢谢!
      

  7.   

    to wthorse()
    我的测试代码是这样的
    string pat = @"<p class=""lastInCell"">(?<part1>.*?) - <a href=.*?>(?<part2>.*?)</a></p></td><td><p class=.*?>.*?<tr.*?><td><p class=.*?>(.*?) - <a href=.*?>(.*?)</a>";
    Regex reg = new Regex(r);
    Match match = reg.Match(htmlCode); // htmlCode为输入数据
    Console.WriteLine(match.Groups["part1"].Value);
    Console.WriteLine(match.Groups["part2"].Value);如果有多条,我怎么动态编写这个表达式,并怎么动态获取我关注的数据呢?
    谢谢!
      

  8.   

    如果只用这个条件
    @"<p class=""lastInCell"">(?<part1>.*?\s*-\s*)<a href=.*?>(?<part2>.*?)</a></p></td>"第一条获取结果为:
    用户配置文件特权提升漏洞 -
    CVE-2006-3443
    正确。第二条信息获取结果为:
    特权提升</p></td><td><p class="lastInCell">重要</p></td><td><p class="lastInCell
    ">低</p></td><td><p class="lastInCell">低</p></td><td><p class="lastInCell">低</
    p></td><td style="border-right: 1px solid rgb(204, 204, 204);"><p class="lastInC
    ell">低</p></td></tr><tr class="evenRecord" valign="top"><td><p class="lastInCel
    l">未处理的异常漏洞 -
    CVE-2006-3648不正确,第二条前面多了一些其他的数据内容。测试代码为:
    string r2 = @"<p class=""lastInCell"">(?<part1>.*?\s*-\s*)<a href=.*?>(?<part2>.*?)</a></p></td>";
    Regex reg = new Regex(r2);
    MatchCollection matches = reg.Matches(htmlCode);System.Collections.IEnumerator enumerator = matches.GetEnumerator();
    while (enumerator.MoveNext() && enumerator.Current != null)
    {
        Match match = (Match)enumerator.Current;
        details = match.Value;
        Console.WriteLine(match.Groups["part1"].Value);
        Console.WriteLine(match.Groups["part2"].Value);
    }
      

  9.   

    <p class="lastInCell">([^<]*)?<a href=".*?name=([^<]*)? target="_blank">
    组1和组2就是你想要的值 
    测试通过
      

  10.   

    to petshop4(开始混正则了) 
    OK了,只是最后多了一个",用replace处理一下就可以了,非常感谢!谢谢大家,结贴给分。
      

  11.   

    string str = "<td id=\"colE3E\">Windows XP Service Pack 1</td><td id=\"colE6E\">Windows XP Service Pack 2</td><td id=\"colECF\">Windows Server 2003</td><td id=\"colEFF\" style=\"border-right: 1px solid rgb(204, 204, 204);\">Windows Server 2003 Service Pack 1</td></tr></thead><tbody><tr class=\"record\" valign=\"top\"><td><p class=\"lastInCell\">用户配置文件特权提升漏洞 - <a href=\"http://www.cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2006-3443\" target=\"_blank\">CVE-2006-3443</a></p></td><td><p class=\"lastInCell\">特权提升</p></td><td><p class=\"lastInCell\">重要</p></td><td><p class=\"lastInCell\">低</p></td><td><p class=\"lastInCell\">低</p></td><td><p class=\"lastInCell\">低</p></td><td style=\"border-right: 1px solid rgb(204, 204, 204);\"><p class=\"lastInCell\">低</p></td></tr><tr class=\"evenRecord\" valign=\"top\"><td><p class=\"lastInCell\">未处理的异常漏洞 - <a href=\"http://www.cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2006-3648\" target=\"_blank\">CVE-2006-3648</a></p></td>";MatchCollection mc = Regex.Matches(str, @"\<p class=""lastInCell""\>([^<]*)\<a [^\>]+\>([^\<]*)\</a\>\</p\>");
    for (int i = 0; i < mc.Count; i++)
    {
    Console.WriteLine(mc[i].Groups[1].Value + mc[i].Groups[2].Value);
    }