求正则表达式 提取table 里面的<td> <tr>的值
- HTML code
<html><HEAD> <LINK href="../css/css.css" type=text/css rel=stylesheet> <LINK href="../css/font.css" type=text/css rel=stylesheet> <script language="JavaScript" src="../js/function.js"></script> <script language="JavaScript" src="../js/comm.js"></script> <script language="JavaScript" src="../js/calendar.js"></script> <META HTTP-EQUIV="Pragma" CONTENT="no-cache"> <META HTTP-EQUIV="Cache-Control" CONTENT="no-cache"> <META HTTP-EQUIV="Expires" CONTENT="0"></HEAD><BODY oncontextmenu="self.event.returnValue=false" onload="window.parent.fraToolbar.Restart();" onkeydown="shortcut();"> <table border='0' cellspacing='0' cellpadding='0' height="18" width=100% background=../image/bg.gif></table> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr height="10"> <td width="10"></td> <td></td> <td width="10"></td> </tr> <tr> <td width="10"></td> <td align="center" valign="top"> <table width="98%" height="100%" style="" id="" border="0" cellspacing="0" cellpadding="0"> <tr height="32"> <td background="/JSSMS/image/tag8.gif" width="7"/> <td background="/JSSMS/image/tag8.gif" > <table border="0" cellspacing="0" cellpadding="0"> <tr height="32"> <td background="/JSSMS/image/tag1.gif" width="12"></td> <td background="/JSSMS/image/tag2.gif" align="center">交易查询</td> <td width="12" background="/JSSMS/image/tag3.gif"></td> <td background="/JSSMS/image/tag7.gif" width="12"></td> <td>请输入查询条件</td> </tr> </table> </td> <td background="/JSSMS/image/tag8.gif" width="3"></td> <td width="3"><img src="/JSSMS/image/tag9.gif" width="3" height="32"></td> </tr> <tr height="3"> <td width="3" class="td1"></td> <td class="td1"></td> <td width="3" class="td1"></td> <td width="3" background="/JSSMS/image/tag11.gif"></td> </tr> <tr> <td width="3" class="td1"></td> <td align="left" valign="top"> <TABLE cellSpacing="2" cellPadding=0 width="100%" align=center border=0"><TBODY> <TR> <TD align="center"> <DIV class="querybox"> <form name="searchForm" action="../rechargeQueryDo.do" method="post"> <input type="hidden" name="btnSave" id="btnSave" value="0" /> <TABLE cellSpacing="0" cellPadding="0" width="95%"> <TBODY> <TR vAlign=middle> <TD width="15%"> <FONT color=#ff6666>查询条件:</FONT> </TD> <TD width="79%"> <TABLE width="450"> <TBODY> <tr> <td noWrap class=ttTable align="center">客户号码:</td> <td noWrap><input type=TEXT onFocus="this.select();" class=edline maxLength=11 onchange=SetFormChanged(this.form); name="clientNo" size="20" value="13661766147" ></td> </tr> <tr> <td noWrap class=ttTable align="center">开始日期:<font color="#FF0000">*</font></td> <td noWrap><script language=javascript>var date1 = new UncCalendar ("startdate", "2012-09-13");date1.display();</script></td> <td noWrap width="50"></td> <td noWrap class=ttTable align="center">结束日期:<font color="#FF0000">*</font></td> <td noWrap><script language=javascript>var date1 = new UncCalendar ("enddate", "2012-09-13");date1.display();</script></td> </tr> </TBODY> </TABLE></TD> <TD align="left" width="8%" nowrap="nowrap"> <A onclick="frmQueryCheck(this);return false;" href="#"><IMG height=23 src="../image/search_btn.gif" border=0></A> </TD> </TR> </TBODY> </TABLE> </form> </DIV> </TD> </TR><TR><TD><TABLE cellSpacing=1 cellPadding=0 width="100%" align=center bgColor=#999999><TBODY><tr bgcolor=#a6dcff><td height="15" class="Tttable" noWrap align="center">充值区域</td><td height="15" class="Tttable" noWrap align="center">流水号</td><td height="15" class="Tttable" noWrap align="center">客户号码</td><td height="15" class="Tttable" noWrap align="center">充值金额</td><td height="15" class="Tttable" noWrap align="center">充值时间</td><td height="15" class="Tttable" noWrap align="center">状态</td><td height="15" class="Tttable" noWrap align="center">处理结果</td><td height="15" class="Tttable" noWrap align="center" >打印</td></tr><tr bgcolor=#e8f7fe onmouseout="javascript:this.bgColor='#e8f7fe';" onmouseover="javascript:this.bgColor='#e8e8e8';"><td height="15" class="td" noWrap align ="center">0280028000</td><td height="15" class="td" noWrap align ="center">0000000033611295</td><td height="15" class="td" noWrap align ="center">13661766147</td><td height="15" class="td" noWrap align ="right">10.00</td><td height="15" class="td" noWrap align ="center">2012-09-13 19:53:54</td><td height="15" class="td" noWrap align ="center">未确认</td><td height="15" class="td" noWrap align ="center">确认短信发送成功</td><td height="15" class="td" noWrap align ="center"></td></tr><tr bgcolor=#e8f7fe onmouseout="javascript:this.bgColor='#e8f7fe';" onmouseover="javascript:this.bgColor='#e8e8e8';"><td height="15" class="td" noWrap align ="center">0280028000</td><td height="15" class="td" noWrap align ="center">0000000033602209</td><td height="15" class="td" noWrap align ="center">13661766147</td><td height="15" class="td" noWrap align ="right">10.00</td><td height="15" class="td" noWrap align ="center">2012-09-13 19:38:40</td><td height="15" class="td" noWrap align ="center">已冲正</td><td height="15" class="td" noWrap align ="center">成功</td><td height="15" class="td" noWrap align ="center"></td></tr><tr bgcolor=#e8f7fe ><TD colspan="15"><DIV align="center">上一页 <select name='everypage' onChange='gotoPage(this.value)'><option value='/JSSMS/rechargeQueryDo.do?btnSave=0&clientNo=13661766147&enddate=2012-09-13&startdate=2012-09-13&perpagenum=10&totalcounts=2&page=1' selected>第1条 至 第2条 共 2条</option></select> 下一页</DIV></TD></tr></TBODY></TABLE> </TD></TR></TBODY></TABLE> </td> <td width="3" class="td1"></td> <td width="3" background="/JSSMS/image/tag11.gif"></td> </tr> <tr height="3"> <td width="3" class="td1"><img src="/JSSMS/image/tag10.gif" width="3" height="3"></td> <td class="td1"></td> <td width="3" class="td1"><img src="/JSSMS/image/tag10.gif" width="3" height="3"></td> <td width="3"><img src="/JSSMS/image/tag12.gif"></td> </tr></table> </td> <td width="10"></td> </tr> <tr height="10"> <td width="10"></td> <td></td> <td width="10"></td> </tr> </table> </BODY><SCRIPT language=javascript><!--msgLang = 1;function frmQueryCheck(thisForm){ window.parent.fraToolbar.Restart(); var clientNo = trim(document.searchForm.clientNo.value); if(clientNo.length != 0){ if (!checkmobile(clientNo, '客户号码')) { document.searchForm.clientNo.focus(); document.searchForm.clientNo.select(); return false; } } window.document.searchForm.submit();}--></SCRIPT></html>
[解决办法]
try...
- C# code
Regex reg = new Regex(@"(?is)<tr bgcolor=#e8f7fe onmouseout=""javascript:this\.bgColor='#e8f7fe';"" onmouseover=""javascript:this\.bgColor='#e8e8e8';"">(?:\s*<td[^>]*>(.*?)</td>)*\s*</tr>");MatchCollection mc = reg.Matches(yourStr);foreach (Match m in mc){ foreach (Capture c in m.Groups[1].Captures) { richTextBox2.Text += c.Value.Trim() + "\n"; } richTextBox2.Text += "----------------------------------\n";}/*-----输出-----028002800000000000336112951366176614710.002012-09-13 19:53:54未确认确认短信发送成功----------------------------------028002800000000000336022091366176614710.002012-09-13 19:38:40已冲正成功----------------------------------*/