javascript中如何通过循环把所有匹配的项列出来?? var text = 'cat, bat, sat, fat'; var pos = text.search(/.at/); while (pos != -1) { alert(pos); var pos = text.search(/.at/); }我这个程序有错误但就是不知道应该怎么做单单一个search()只能匹配第一个,我想要全部匹配掉 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 var text = 'cat, bat, sat, fat',reg=/.at/g; while ( m= reg.exec(text)) alert( m )或者 text.replace(/.at/g,function(s){ alert(s) }) var text='cat, bat, sat, fat';var re=/.at/g;var match;while((match=re.exec(text))!=null){alert(match);} LZ可以这样写:var text = 'cat, bat, sat, fat';var pos = text.match(/.at/g);for(var i = 0; i < pos.length; i++) { alert(pos[i]);} var text = 'cat, bat, sat, fat'; var pos = text.match(/.at/g); //while (pos != -1) { alert(pos); // var pos = text.search(/.at/); //} 但是search不行吗??我想用循环的方式 search,match不会移动exec可以text.replace(/.at/g,function(s,i){ alert(i) }) 这样也可以获得位置 它忽略 regexp 的 lastIndex 属性 js 缩放网页的问题 js 帮忙改下 正则表达式 一个Form4个Submit用JS就是不好使!望指点!! 退出页面的问题? 请教:我的一个页面有两个框架。分别载有两个页面。。我想通过一个页面刷新别一个页面在: 怎样在<script></script>标签里面嵌套包含<script></script> 请问关于在子窗口中选择多值以后传递给父窗口中一个多值域的问题! 如何自动关闭本页? 求js中数组转变成json格式字符串方法 我遇到一个问题,就是我想单独运行下面的一段代码得到运行结果,但我不知道在eclipse中怎么运行,拜托大神指点一下 fusionchart统计图 请教js的一个弹窗问题
while ( m= reg.exec(text)) alert( m )
或者
text.replace(/.at/g,function(s){ alert(s) })
var re=/.at/g;
var match;
while((match=re.exec(text))!=null){
alert(match);
}
var pos = text.match(/.at/g);
for(var i = 0; i < pos.length; i++) {
alert(pos[i]);
}
var pos = text.match(/.at/g);
//while (pos != -1) {
alert(pos);
// var pos = text.search(/.at/);
//}
exec可以
text.replace(/.at/g,function(s,i){ alert(i) })
这样也可以获得位置