我要的是可以用的正则表达式 谢谢~

<td colspan="2">SV Kapfenberg - Rapid Wien <a href="javascript:openResizeAbleWindow('redirStats.aspx?url=aHR0cDovL3d3dy5zdGF0cy5iZXRyYWRhci5jb20vc3RhdGlzdGljcy9saXZlc2NvcmVjYy8/bWF0Y2hpZD03NzU1OTUmdHJlZW1lbnU9ZmFsc2UmbGFuZ3VhZ2U9ZGU=&cid=1906', 'statistics', 756, 650, true)"> <img class='MatchStatImg' src='pic/table/symbol_spielstatistik.gif' /> </a> </td>

<td colspan="2">SV Kapfenberg - Rapid Wien </td>

现在就要匹配 <td> </td>之间的内容
得到结果
SV Kapfenberg - Rapid Wien
SV Kapfenberg - Rapid Wien

再来第二个 不好意思了 呵呵
<td class="OT_Col_Odd_BR"
onMouseOut="javascript:this.className='OT_Col_Odd_BR'" onMouseOver="javascript:this.className='OT_Col_Odd_BR_Over'"
id='814986_1'
onclick="javascript:f_addToBetslip(this,814986,'5.00', 'SV Kapfenberg - Rapid Wien ', 1, 296067, 'True', 3, 'Tipp', '1')">
5,00
</td>

<td class="OT_Col_Odd_BR"
onMouseOut="javascript:this.className='OT_Col_Odd_BR'" onMouseOver="javascript:this.className='OT_Col_Odd_BR_Over'"
id='817169_1'
onclick="javascript:f_addToBetslip(this,817169,'2.70', 'DSV Leoben - FK Austria Magna (A) ', 1, 296691, 'True', 3, 'Tipp', '1')">
2,70
</td>

得出结果
5,00
2,70
页面上有很多td 并且td中的有些数据是不想要的
用内文本的方法是拿不出来的了

我这要用的是PHP

慕勒3428872
浏览 188回答 3
3回答

茅侃侃

正则表达式如下:问题1:正则表达式: \<td colspan=\"2\"\>.*?\<a href.*?被测试字符串:<td colspan="2">SV Kapfenberg - Rapid Wien <a href="javascript:openResizeAbleWindow('redirStats.aspx?测试结果为:array[0] = '<td colspan="2">SV Kapfenberg - Rapid Wien <a href'array[1] = '<td colspan="2">'array[2] = 'SV Kapfenberg - Rapid Wien 'array[3] = '<a href'问题2:正则表达式: .*?javascript:f_addToBetslip\(this,817169,\'(.*?)\',.*?被测试字符串:onclick="javascript:f_addToBetslip(this,817169,'2.70', 'DSV Leoben - FK Austria Magna (A) ', 1, 296691, 'True', 3, 'Tipp', '1')">测试结果:array[0] = 'onclick="javascript:f_addToBetslip(this,817169,'2.70','array[1] = '2.70'

素胚勾勒不出你

td.innerText 就是你要的内容,不需要用正则测试代码:<html><head><script>function wahaha(){for(var i=0; i<x.cells.length; i++){alert(x.cells[i].innerText);}for(var i=0; i<y.cells.length; i++){alert(y.cells[i].innerText);}}</script></head><body onload="wahaha()"><table><tr id="x"><td colspan="2">SV Kapfenberg - Rapid Wien <a href="javascript:openResizeAbleWindow('redirStats.aspx?url=aHR0cDovL3d3dy5zdGF0cy5iZXRyYWRhci5jb20vc3RhdGlzdGljcy9saXZlc2NvcmVjYy8/bWF0Y2hpZD03NzU1OTUmdHJlZW1lbnU9ZmFsc2UmbGFuZ3VhZ2U9ZGU=&cid=1906', 'statistics', 756, 650, true)"> <img class='MatchStatImg' src='pic/table/symbol_spielstatistik.gif' /> </a> </td><td colspan="2">SV Kapfenberg - Rapid Wien </td></tr><tr id="y"><td class="OT_Col_Odd_BR"onMouseOut="javascript:this.className='OT_Col_Odd_BR'" onMouseOver="javascript:this.className='OT_Col_Odd_BR_Over'"id='814986_1'onclick="javascript:f_addToBetslip(this,814986,'5.00', 'SV Kapfenberg - Rapid Wien ', 1, 296067, 'True', 3, 'Tipp', '1')">5,00</td><td class="OT_Col_Odd_BR"onMouseOut="javascript:this.className='OT_Col_Odd_BR'" onMouseOver="javascript:this.className='OT_Col_Odd_BR_Over'"id='817169_1'onclick="javascript:f_addToBetslip(this,817169,'2.70', 'DSV Leoben - FK Austria Magna (A) ', 1, 296691, 'True', 3, 'Tipp', '1')">2,70</td></tr></table></body></html>

LEATH

下面的代码是你要的:<script type="text/javascript" language="javascript">function GetAnswer() {var o = document.getElementById("txt")alert(o.value.replace(/<\/?.+?>/g,""));}</script><input type="text" id="txt" style="width: 292px; height: 226px" value="" /><input type="button" value="GetAnswer" onclick="return GetAnswer();" />======================================补充======================================php里你自己的测一下了<?php$a="准备过滤的源字符串";$i = preg_replace("/<\/?.+?>/","",$a);echo $i;?>
打开App,查看更多内容
随时随地看视频慕课网APP