高手帮忙看看这个比较有难度的正则表达式(只有给10分权限)
<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 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里做二次处理