新人学习正则表达式
想提举下面代码中的 id="14002"和
          中国长江黄河这么2个值
我用(<tr\s*id="[0-9]*"|[^<>]+?(?=</div></td>))提取出来的时候包括了 发布时间 用户名 发布人等信息, 如何去掉这些不需要的内容
<table width="100%" cellpadding="0" cellspacing="0" border="1" style="border-bottom:#ffffff 1px solid;" bordercolordark="White" bordercolorlight="Black">
  <tr height="25"> 
    <td  width="60%" style="border-bottom:#001177 1px solid;"><div align="center"> 
        标题</div></td>
    <td width="10%" style="border-bottom:#001177 1px solid;"><div align="center">发布时间</div></td>
    <td width="10%" style="border-bottom:#001177 1px solid;"><div align="center">用户名</div></td>
    <td width="10%" style="border-bottom:#001177 1px solid;"><div align="center">发布人IP</div></td>
    <td width="10%" style="border-bottom:#001177 1px solid;"><div align="center"> 
        操作</div></td>
  </tr>
  
  <tr id="14002" onmouseover="mouseover me" onmouseout="mouseout me" onclick="clickit me" language="vbscript" height="25"> 
    <td align="center"><div align="left"><img src="images/gca.gif" WIDTH="11" HEIGHT="11"> 
        &nbsp;&nbsp;中国长江黄河</div></td>
    <td align="center">2007-1-7 15:09:31</td>
    <td align="center">fadfac</td>
    <td align="center">192.168.0.1</td>
    <td align="center"><a href="news.aspx?id=14002" target="_blank">查看</a></td>
  </tr>

解决方案 »

  1.   

    string str = @"<table width=""100%"" cellpadding=""0"" cellspacing=""0"" border=""1"" style=""border-bottom:#ffffff 1px solid;"" bordercolordark=""White"" bordercolorlight=""Black"">
      <tr height=""25""> 
        <td  width=""60%"" style=""border-bottom:#001177 1px solid;""><div align=""center""> 
            标题</div></td>
        <td width=""10%"" style=""border-bottom:#001177 1px solid;""><div align=""center"">发布时间</div></td>
        <td width=""10%"" style=""border-bottom:#001177 1px solid;""><div align=""center"">用户名</div></td>
        <td width=""10%"" style=""border-bottom:#001177 1px solid;""><div align=""center"">发布人IP</div></td>
        <td width=""10%"" style=""border-bottom:#001177 1px solid;""><div align=""center""> 
            操作</div></td>
      </tr>
      
      <tr id=""14002"" onmouseover=""mouseover me"" onmouseout=""mouseout me"" onclick=""clickit me"" language=""vbscript"" height=""25""> 
        <td align=""center""><div align=""left""><img src=""images/gca.gif"" WIDTH=""11"" HEIGHT=""11""> 
            &nbsp;&nbsp;中国长江黄河</div></td>
        <td align=""center"">2007-1-7 15:09:31</td>
        <td align=""center"">fadfac</td>
        <td align=""center"">192.168.0.1</td>
        <td align=""center""><a href=""news.aspx?id=14002"" target=""_blank"">查看</a></td>
      </tr>";

    Regex reg= new Regex(@"<tr\s*id=""([^""]*?)""[^>]*?>\s*<td[^>]*?>([\s\S]*?)</td>"); MatchCollection  ms = reg.Matches(str);
    if(ms.Count>0)
    {
    string sValue  = ms[0].Result("$1");

    Response.Write(sValue +"<BR>") ;
    sValue  = ms[0].Result("$2");
    sValue = Regex.Replace(sValue,"<[^>]*?>","");
    Response.Write(sValue);
    }
      

  2.   

    string yourStr = ......;
    MatchCollction mc = Regex.Matches(yourStr, "<tr\\s+(id=\".+?\").+?>\\s*<td.+?>\\s*<div.+?><img.+?>([\\s\\S]+?)</div>", RegexOptions.IgnoreCase);
    foreach(Match m in mc)
    {
        m.Groups[1].Value;//id=
        m.Groups[2].Value;//
    }