马上过十一了,救命问题,那位大哥给我来个正则表达式?

arden1019 2006-09-30 10:15:44
几乎没有HTML和C#经验,现在需要解析一个html中的table。代码如下:

<tr bgcolor="#CEDEFF"><td><div align="center"><font color="#003399">09/30</font></div></td>
<td><div align="center"><font color="#003399">09:00</font></div></td>
<td><div align="center"><font color="#003399">09:00</font></div></td>
<td><div align="center"><font color="#003399"><img src="../images/airlogo/el.gif" alt="logo" width="29" height="20"></font></div></td>
<td><font color="#003399"><a href="airline_c.jsp?airlinecode=EL">中国航空</a></font></td>
<td><div align="center"><font color="#003399">EL</font></div></td>
<td><div align="center"><font color="#003399">2108</font></div></td>
<td><div align="center"><font color="#003399">香港</font></div></td>
<td><div align="center"><font color="#003399">曼谷</font></div></td>
<td><div align="center"><font color="#003399">C1</font></div></td>
<td bgcolor="#CEDEFF"><div align="center"><font color="#003399">2</font></div></td>
<td bgcolor="#CEDEFF"><div align="center"><font color="#003399">A330-300</font></div></td>
<td><div align="center"><font color="#003399">准时</font></div></td>
</tr>

要求能提取出其中的一下信息:

09/30 09:00 09:00 中国航空 EL 2108 香港 曼谷 C1 2 A330-300 准时

急切求救中,为了哥们能过好十一 :)

那位大大给我来个正则表达式
...全文
199 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
arden1019 2006-09-30
  • 打赏
  • 举报
回复
节后散分吧哈哈
arden1019 2006-09-30
  • 打赏
  • 举报
回复
多谢各位热心的兄弟
kissknife 2006-09-30
  • 打赏
  • 举报
回复
如果楼主的html格式都是上面给出的那样,试试:
regex r=new regex(@">([^<]+)<");
string s="";
matchcollection mc=r.matches(html);
foreach(match m in mc)
{
s += m.groups[1].value+" ";
}
echi0711 2006-09-30
  • 打赏
  • 举报
回复
帮忙顶!
hbx1982 2006-09-30
  • 打赏
  • 举报
回复
跟着学习了!
POPO_POPO 2006-09-30
  • 打赏
  • 举报
回复
Regex reg=new Regex"(?<=<td><div align=\"center\"><font color=\"#003399\">)((?:(?!<img).)*?)(?=</font></div></td>)");
string res="";
foreach( Match m in reg.Matches(strYourHtml))
{
res+=m.Value+" ";
}
Nara 2006-09-30
  • 打赏
  • 举报
回复
赞同junsir()的意见,正则不是很保险的说
petshop4 2006-09-30
  • 打赏
  • 举报
回复
Regex reg=new Regex(@"(?<=>)[^\r\n<>]+?(?=<)");
string res="";
foreach( Match m in reg.Matches(strYourHtml))
{
res+=m.Value+" ";
}
petshop4 2006-09-30
  • 打赏
  • 举报
回复
Regex reg=new Regex"(?<=<td><div align=\"center\"><font color=\"#003399\">)((?:(?!<img).)*?)(?=</font></div></td>)");
string res="";
foreach( Match m in reg.Matches(strYourHtml))
{
res+=m.Value+" ";
}
xlshen_lxz 2006-09-30
  • 打赏
  • 举报
回复
试验过cancerser的方法了,可以的。不过提醒LZ要添加
using System.Text.RegularExpressions;
zhqs1000 2006-09-30
  • 打赏
  • 举报
回复
阿笨
xlshen_lxz 2006-09-30
  • 打赏
  • 举报
回复
学习
cancerser 2006-09-30
  • 打赏
  • 举报
回复
Regex reg=new Regex(@"(?<=\>)[^ |\>]+(?=\<)");
string res="";
foreach( Match m in reg.Matches(strYourHtml))
{
res+=m.Value+" ";
}
junsir 2006-09-30
  • 打赏
  • 举报
回复
你的Table是不是服务器控件?
是:在后台里遍历表中的记录。
不是:在前台用JS读。
用正则表达式??
没必要用吧?
也不好用。

110,546

社区成员

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

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

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