正则查找问题..
有个页面,其中有如下内容,可能不只3个
<table> <td "> <a id= "_$portlet_aaaaaaa_td3 " title= " " ...> <img src= "... "> </a> </td> </table>
<table> <td "> <a id= "_$portlet_bbbb_td3 " title= " " ...> <img src= "... "> </a> </td> </table>
<table> <td "> <a id= "_$portlet_cccccccc_td3 " title= " " ...> <img src= "... "> </a> </td> </table>
是否可以通过正则查找的所有的以上格式的id
其中id的格式是中间部分不一样..
谢谢先啦。。
------解决方案-------------------- <textarea id=textarea1>
<table> <td "> <a id= "_$portlet_aaaaaaa_td3 " title= " " ...> <img src= "... "> </a> </td> </table>
<table> <td "> <a id= "_$portlet_bbbb_td3 " title= " " ...> <img src= "... "> </a> </td> </table>
<table> <td "> <a id= "_$portlet_cccccccc_td3 " title= " " ...> <img src= "... "> </a> </td> </table>
</textarea>
<script>
alert(aaa(textarea1.value))
function aaa(x)
{
var rtn= " ";
var arr = x.match(/id=\ "_\$portlet_.*?_td3\ "/ig);
for(i=0;i <arr.length;i++)
{
rtn += arr[i] + "\n ";
}
return(rtn);
}
</script>
------解决方案--------------------上午有人问过,俺答的不好,不过这回还不错,哈
<body>
<table> <td> <a id= "_$portlet_aaaaaaa_td3 " title= " "> <img src= "... "> </a> </td> </table>
<table> <td> <a id= "_$portlet_bbbb_td3 " title= " "> <img src= "... "> </a> </td> </table>
<table> <td> <a id= "_$portlet_cccccccc_td3 " title= " "> <img src= "... "> </a> </td> </table>
<table> <td> <a id= "aNormal " title= " "> <img src= "... "> </a> </td> </table>
<script language= "JavaScript ">
<!--
var colAllA = document.getElementsByTagName( "* ");
var re = /^_\$portlet.*_td3$/;
for (var i=0; i <colAllA.length; i++)
{
if (colAllA[i].id && re.test(colAllA[i].id))
alert(colAllA[i].id);
}
//-->
</script>
</body>