3 回答
TA贡献1842条经验 获得超21个赞
正则表达式如下:
问题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'
TA贡献1827条经验 获得超9个赞
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>
TA贡献1936条经验 获得超6个赞
下面的代码是你要的:
<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;
?>
- 3 回答
- 0 关注
- 187 浏览
添加回答
举报