<tr>
<td align="left">
<table width="700" border="0" align="center" cellpadding="0" cellspacing="0" class="unnamed1">
<tr align="left">
<td >
<font color='red'>Aegwynn US-Horde
</td>
<td width="134" align="right">
<font color='red'>0.54 </font>
<font color='red'>元</font>/
<font color='red'>Gold</font>
</td>
<td width="132" align="right"><font color="535353">
<font color='red'>30-2000</font></font></td>
<td width="80" align="center"><font color="535353">
<font color='red'>紧急</font>
</font></td>
<td width="58" height="25" align="center">
<a href='UserOrderTwo.aspx?id=013,002,001' onclick='return checkUserName()' ><img src='pic/nv_hidden.gif' width='14' height='14' border='0'></a></td>
</tr>
</table>
</td></tr>
<tr><td>
<img src="pic/line1.jpg" width="100%" height="1" alt="" /></td>
</tr>
<tr>
<td align="left">
<table width="700" border="0" align="center" cellpadding="0" cellspacing="0" class="unnamed1">
<tr align="left">
<td >
Aerie'peak US-Alliance
</td>
<td width="134" align="right">
0.50
元/
Gold
</td>
<td width="132" align="right"><font color="535353">
30-482</font></td>
<td width="80" align="center"><font color="535353">
正常
</font></td>
<td width="58" height="25" align="center">里面有两中状态,一为"正常",一为"紧急".我想把这两种情况一起抓取.
这是我的表达式但还是只能抓取"正常"情况.
string p = @"<td >(<font[^>]*?>)?(?<area>[^-]*?)-(?<type>[^<]*?)</td>\s+<td[^>]*?>\s+(<font[^>]*?>)?(?<price>\S+)(</font>)?\s+(<font[^>]*?>)?\S+\s+(</font>/)?\s+(<font[^>]*?>)?\S+(</font>)?\s+</td>\s+<td[^>]*?><font[^>]*?>\s+(<font[^>]*?>)?(?<num>[^<]*?)(</font>)?</font></td>\s+<td[^>]*?><font[^>]*?>\s+(<font[^>]*?>)?(?<state>\S+)(\s+</font>)?\s+</font></td>";
<td align="left">
<table width="700" border="0" align="center" cellpadding="0" cellspacing="0" class="unnamed1">
<tr align="left">
<td >
<font color='red'>Aegwynn US-Horde
</td>
<td width="134" align="right">
<font color='red'>0.54 </font>
<font color='red'>元</font>/
<font color='red'>Gold</font>
</td>
<td width="132" align="right"><font color="535353">
<font color='red'>30-2000</font></font></td>
<td width="80" align="center"><font color="535353">
<font color='red'>紧急</font>
</font></td>
<td width="58" height="25" align="center">
<a href='UserOrderTwo.aspx?id=013,002,001' onclick='return checkUserName()' ><img src='pic/nv_hidden.gif' width='14' height='14' border='0'></a></td>
</tr>
</table>
</td></tr>
<tr><td>
<img src="pic/line1.jpg" width="100%" height="1" alt="" /></td>
</tr>
<tr>
<td align="left">
<table width="700" border="0" align="center" cellpadding="0" cellspacing="0" class="unnamed1">
<tr align="left">
<td >
Aerie'peak US-Alliance
</td>
<td width="134" align="right">
0.50
元/
Gold
</td>
<td width="132" align="right"><font color="535353">
30-482</font></td>
<td width="80" align="center"><font color="535353">
正常
</font></td>
<td width="58" height="25" align="center">里面有两中状态,一为"正常",一为"紧急".我想把这两种情况一起抓取.
这是我的表达式但还是只能抓取"正常"情况.
string p = @"<td >(<font[^>]*?>)?(?<area>[^-]*?)-(?<type>[^<]*?)</td>\s+<td[^>]*?>\s+(<font[^>]*?>)?(?<price>\S+)(</font>)?\s+(<font[^>]*?>)?\S+\s+(</font>/)?\s+(<font[^>]*?>)?\S+(</font>)?\s+</td>\s+<td[^>]*?><font[^>]*?>\s+(<font[^>]*?>)?(?<num>[^<]*?)(</font>)?</font></td>\s+<td[^>]*?><font[^>]*?>\s+(<font[^>]*?>)?(?<state>\S+)(\s+</font>)?\s+</font></td>";
解决方案 »
- 求一个正则表达式,目前头昏脑涨中。
- 最近在研究.NET4.0中的Data Entity Framework, 有一些疑问向大家请教.
- 关于C#多线程操作界面的控件怎么办
- 请确保此代码文件中定义的类与“inherits”属性匹配,并且该类扩展的基类(例如 Page 或 UserControl)是正确的。
- 问一个有关网页鼠标事件,谢谢了
- 一个FlexGrid的问题和一个繁体操作系统的问题(100分)
- XML中操作的问题,进来看看.
- static 、public定义变量的问题!!!初学者,急呀。。。
- folderBrowserDialog为什么不能完整显示啊?
- WinForm程序,控件不要跟随父容器字体变化
- 打凭证不同打印机不同效果?怎么解决
- vs2005 使用ODBC错误
改成这样的还是同样的结果...帮帮忙啊.....
就这个问题.谢谢
<td width="134" align="right">
<font color='red'>0.54 </font>
<font color='red'>元</font>/
<font color='red'>Gold</font>
</td> <td width="134" align="right">
0.50
元/
Gold
</td>这种情况如果“紧急”和“正常”的格式分别保持一致,可以分开来抓取,正则写起来比较清晰,效率也会高些,现在这样写在一起很麻烦,而且效率也不会高,如果一定要保证抓取顺序,那就先<td>[\s\S]*?</td>把price这一部分全取出来,在foreach里做二次处理
对,两种情况分别抓取..
谢谢了.
我先试试,因为这个没必要保证顺序
怎么没得到结果啊??
(<font[^>]*?>)?
(<font[^>]*?>){0,1}
最新修改:
<td >\s+<font[^>]*?>(?<area>[^-]*?)-(?<type>[^<]*?)</td>\s+<td[^>]*?>\s+<font[^>]*?>(?<price>\S+)\s+</font>\s+<font[^>]*?>\S+\s+</font>/\s+<font[^>]*?>\S+</font>\s+</td>\s+<td[^>]*?><font[^>]*?>\s+<font[^>]*?>(?<num>[^<]*?)</font></font></td>\s+<td[^>]*?><font[^>]*?>\s+<font[^>]*?>(?<state>\S+)\s+</font>\s+</font></td>还是不行
我的表达式是要存在数据库的,怎样存这两个?
用,隔开,用SPLIT,然后FOREACH ??
<td >\s+(<font[^>]*?>)?(?<area>[^-]*?)-(?<type>[^<]*?)</td>\s+<td[^>]*?>\s+(<font[^>]*?>)?(?<price>[^<]*?)(</font>)?\s+(<font[^>]*?>)?[^<]*?(</font>/\s+)?(<font[^>]*?>[^<]*?</font>\s+)?</td>\s+<td[^>]*?><font[^>]*?>\s+(<font[^>]*?>)?(?<num>[^<]*?)(</font>)?</font></td>\s+<td[^>]*?><font[^>]*?>\s+(<font[^>]*?>)?(?<state>[^<]*?)(</font>)?\s+</font>产生结果448 = 前面的366+82
@"<td >(?<area>[^-]*?)-(?<type>[^<]*?)</td>\s+<td[^>]*?>\s+(?<price>\S+)[^<]*?</td>\s+<td[^>]*?><font[^>]*?>(?<num>[^<]*?)</font></td>\s+<td[^>]*?><font[^>]*?>(?<state>[^<]*?)</font></td>" 结果:366条 时间:29.36秒@"<td >\s+<font[^>]*?>(?<area>[^-]*?)-(?<type>[^<]*?)</td>\s+<td[^>]*?>\s+<font[^>]*?>(?<price>[^<]*?)</font>\s+<font[^>]*?>[^<]*?</font>/\s+<font[^>]*?>[^<]*?</font>\s+</td>\s+<td[^>]*?><font[^>]*?>\s+<font[^>]*?>(?<num>[^<]*?)</font></font></td>\s+<td[^>]*?><font[^>]*?>\s+<font[^>]*?>(?<state>[^<]*?)</font>";
结果:82条 时间:29.31秒
<td >\s+(<font[^>]*?>)?(?<area>[^-]*?)-(?<type>[^<]*?)</td>\s+<td[^>]*?>\s+(<font[^>]*?>)?(?<price>[^<]*?)(</font>)?\s+(<font[^>]*?>)?[^<]*?(</font>/\s+)?(<font[^>]*?>[^<]*?</font>\s+)?</td>\s+<td[^>]*?><font[^>]*?>\s+(<font[^>]*?>)?(?<num>[^<]*?)(</font>)?</font></td>\s+<td[^>]*?><font[^>]*?>\s+(<font[^>]*?>)?(?<state>[^<]*?)(</font>)?\s+</font> 结果:448条 时间:29.65秒.过客兄进来看看,好象经过RegexOptions.Compiled 过后的效率都差不多...
想听听各位高见...