javascript如何查找指定"<a><b>1111</b><b>2222</b></a>"中的"<b>"与"</b>"的所有字符
也就是找出 "1111 "与 "2222 ",
用下面这样只能找出 "1111 ":
var str= " <a> <b> 1111 </b> <b> 2222 </b> </a> ";
var re = / <b> (.*?) <\/b> /gi;
re.test(str)
str=RegExp.$1;
alert(str);
------解决方案-------------------- <script>
var str= " <a> <b> 1111 </b> <b> 2222 </b> </a> ";
var re = /( <b> (.*?) <\/b> )/gi;
alert(aaa(str));
function aaa(x)
{
var rtn= " ";
var arr = x.match(re);
for(i=0;i <arr.length;i++)
{
rtn += arr[i].replace(re, "$2 ") + "\n ";
}
return(rtn);
}
</script>
------解决方案--------------------var str= " <a> <b> 1111 </b> <b> 2222 </b> </a> ";
var arr = new Array();
str.replace(/ <b> (.*?) <\/b> /gi, function(){arr.push(arguments[1]);return " ";})
alert(arr);//数组里是所有匹配出来的String