怎样去除非匹配<td>.*</td>的html?

解决方案 »

  1.   

    not sure if the following is what you want,  string s = "....";
    s = Regex.Replace(s, @"<(?!td)(\S+)[^>]*>.*?</\1>","",RegexOptions.IgnoreCase);
    Console.WriteLine(s);since if you have <tr><td>..</td></tr>, then you will have nothing left, consider to match <td>.*?</td>, then remove other parts of the string
      

  2.   

    string html = ??;
    string temp1 = html;
    string temp2;
    html = "";while (temp1.Length > 0)
    {
        if (temp1.Substring("<td>") < 0)
        {
            break;
        }    temp1 = temp1.Substring(html.IndexOf("<td>"));
        temp2 = temp1.Substring(0, html.IndexOf("</td>" + 6);
        html += temp2;
    }