匹配<th>key1111</th>\r\t\n<td>values1111</td>
自己写了个 不对“<th>(?<key>.*?)</th>(\\s*)<td>(?<value>.*?)</td>”

解决方案 »

  1.   


    string s = @"
    <th>key1111 </th><td>values1111 </td>
    ";
    System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex("<th>(.*?)</th>(?:.|\n)*?<td>(.*?)</td>");
    System.Text.RegularExpressions.MatchCollection matches = regex.Matches(s);
    Console.WriteLine(matches[0].Groups[2]);
      

  2.   


            string s = @"
    <th>key1111 </th><td>values1111 </td>
    ";
            Match result = Regex.Match(s, "<th[^>]*>(?<title>[^<]*)</th>[^<]*<td[^>]*>(?<value>[^<]*)</td>");
            Response.Write(result.Groups["title"]);
            Response.Write(result.Groups["value"]);