javascript regular expression. regex exec函数

<body>
<input type="text" id="txtInput"  /> <input type="button"  onclick="check()" value="check"  />
<br /><br /> <hr />

<script type="text/javascript" >
function check(){
	var re=/(1)((2)3)/g;
	var arr;
	var src =document.getElementById("txtInput").value ;
	
	document.write(src + "<br>");

	while ((arr = re.exec(src)) != null)
	// debugger;		//arr返回一个数组.length为(组)的个数,
	if(arr!=null){
       document.write('test:'+arr[1]+',idx:'+ arr.index + ",LastIdx:" + arr.lastIndex + ",Value:" + arr+ "<br>");
	}else {alert('null');}
}
/*
d123d123
test:1,idx:1,LastIdx:4,Value:123,1,23,2
test:1,idx:5,LastIdx:8,Value:123,1,23,2
*/
</script>
</body>
</html>
posted @ 2010-10-09 18:15  庚武  Views(688)  Comments(0Edit  收藏  举报