求个正则匹配两个连续的HTML标签并取出标签中的值

伊羽 2009-02-12 03:07:31
匹配<th>key1111</th>\r\t\n<td>values1111</td>
自己写了个 不对“<th>(?<key>.*?)</th>(\\s*)<td>(?<value>.*?)</td>”
...全文
154 3 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
伊羽 2009-02-14
  • 打赏
  • 举报
回复
我那个其实是对的。。。
symbol441 2009-02-12
  • 打赏
  • 举报
回复

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"]);

NSnaiL 2009-02-12
  • 打赏
  • 举报
回复

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]);

111,092

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧