大家帮个忙,刚接触正则表达式

7in10 2006-11-17 02:16:13
<table>
<tr>
<td>
最新咨询
</td>
</tr>
</table>
<table>
<tr>
<td class="a">aaaaaaaaaaaaaaaaaaaaaaaaaaa</td>
<td class="a">bbbbbbbbbbbbb</td>
<td class="a">ccccccccccccc</td>
<td class="a">ddddddddddddddddddddddddd</td>
</tr>
</table>
<table>
<tr>
<td>
热辣新闻
</td>
</tr>
</table>
<table>
<tr>
<td class="a">eeeeeeeeeee</td>
<td class="a">ffffffffffffffffffff</td>
<td class="a">ggggggggggggggggg</td>
<td class="a">hhhhhhhhhhhhhhhhhhhh</td>
</tr>
</table>
<table>
<tr>
<td>
最新行情
</td>
</tr>
</table>
<table>
<tr>
<td class="a">iiiiiiiiiiiiiiii</td>
<td class="a">jjjjjjjjjjjjjjjjjjjjjjj</td>
<td class="a">lllllllllllllllllllllllllllll</td>
<td class="a">kkkkkkkkkkkkk</td>
</tr>
</table>

原数据如上。如何从上段代码中提取到热辣新闻后面一个的table中td里的数据?
也就是,eeeeeeeeee,ffffffffffffff,gggggggggggggg,hhhhhhh这些数据?
谢谢~~~~
...全文
108 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
luck0235 2006-11-26
  • 打赏
  • 举报
回复
using System.Text;
using System.Text.RegularExpressions;
using System.IO;

string html = "...";//整个html
string result = "";//某个<td class="a">与</td>之间的字符串

MatchCollection mc = Regex.Matches(html, "<td class=\"a\">(?<arr>.+?)</td>", RegexOptions.IgnoreCase);

//注:截取页面中所有<td class="a">与</td>之间的字符串并按顺序存为数组
//判断一下你需要的数据是在数组中的位置然后输入i
result = mc[i].Groups["arr"].Value.Trim();
feifeiyaqi3 2006-11-26
  • 打赏
  • 举报
回复
贴代码啊
我看你有戏 2006-11-26
  • 打赏
  • 举报
回复
你把html代码如实的贴出来

这样会好办一点
7in10 2006-11-17
  • 打赏
  • 举报
回复
每人看哦?

110,534

社区成员

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

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

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