日期:2014-05-18  浏览次数:20553 次

正则表达式?
我想用正则表达式把 <td   ..class= "td1 "> 的内容找出来

<table>
<tr>
<td   width= "130 "     align= "center "   class= "td1 "> asdgd1 </td>
<td   width= "130 "     align= "center "   class= "td1 "> asdgd1 </td>
<td   width= "130 "     align= "center "   class= "td1 "> asdgd1 </td>
<td   width= "130 "     align= "center "   class= "td1 "> asdgd1 </td>
</tr>
<tr>
<td   width= "130 "     align= "center "   class= "td1 "> asdgd2 </td>
<td   width= "130 "     align= "center "   class= "td1 "> asdgd2 </td>
<td   width= "130 "     align= "center "   class= "td1 "> asdgd2 </td>
<td   width= "130 "     align= "center "   class= "td1 "> asdgd2 </td>
</tr>
</table>

<table>
<tr>
<td   width= "130 "     align= "center "   class= "td1 "> asdgd1 </td>
<td   width= "130 "     align= "center "   class= "td1 "> asdgd1 </td>
<td   width= "130 "     align= "center "   class= "td1 "> asdgd1 </td>
<td   width= "130 "     align= "center "   class= "td1 "> asdgd1 </td>
</tr>
<tr>
<td   width= "130 "     align= "center "   class= "td1 "> asdgd2 </td>
<td   width= "130 "     align= "center "   class= "td1 "> asdgd2 </td>
<td   width= "130 "     align= "center "   class= "td1 "> asdgd2 </td>
<td   width= "130 "     align= "center "   class= "td1 "> asdgd2 </td>
</tr>
</table>

------解决方案--------------------
windstore(雪海飄香) 的正则进步很快,再注意一些细节,我就可以卸甲归田了

<td[\S\s]+? 这里的[\S\s]+?用不会产生歧义的贪婪匹配[^> ]*会提高效率

字符串前加了@,用 " "对 "进行转义即可,不需要再加\

(? <content> [\S\s]+?) 这里也是,视需求而定,如果这里不出现“ <”字符,可以用[^ <]*,否则用[\s\S]*?好一些,因为有时候可能是 <td...> </td> 这种空字符的情况