当前位置:编程学习 > JS >>

javascript IE的RegExp.exec


var st="A[B]C[D]E[F]G";
var reg =/[w]/ig;
var s1 = st.replace(reg,"");
var s2=[];
var arr;
while((arr=/[w]/ig.exec(st))!=null)s2.push(arr[0]);
alert(s1);
alert(s2.join(""));


var st="A[B]C[D]E[F]G";
var reg =/[w]/ig;
var s1 = st.replace(reg,"");
var s2=[];
var arr;
while((arr=reg.exec(st))!=null)s2.push(arr[0]);
alert(s1);
alert(s2.join(""));


var rx = /<a href=['"](.*)['"]>.*</a>/g;
var s='<a href="x">X</a>n<a href="y">Y</a>n<a href="z">Z</a>n';
document.write('Found the following link URLs in the string:<br/><ul>');
while (matches = rx.exec(s)) {
document.write('<li>' + matches[1] + '</li>n');
}
document.write('</ul>');


var s='<a href="x">X</a>n<a href="y">Y</a>n<a href="z">Z</a>n';
document.write('Found the following link URLs in the string:<br/><ul>');
while (matches = /<a href=['"](.*)['"]>.*</a>/g.exec(s)) {
document.write('<li>' + matches[1] + '</li>n');
}
document.write('</ul>');

补充:网页制作,js教程 
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,