注册 登录
编程论坛 JavaScript论坛

大家好,新人想问下

qidi45a 发布于 2017-06-18 22:33, 1765 次点击
var sstr = "Now is the time and this is the time and that is the time";
var patt = /t\w*e/g;
var str = '';
var maAr = patt.exec(sstr);
alert(maAr[0]);//为什么一定直接写maAr辉报错,要写成maAR[0]。maAr是数组吗?
alert(maAr.index);//这里返回的是位置7,现在弄不懂maAr是什么数据类型

var sstr = "Now is the time and this is the time and that is the time";
var patt = /t\w*e/g;
var maAr;
var str = '';
while((maAr = patt.exec(sstr)) != null){      //这里的exec为什么每次只返回一个字符串给maAr,并不是一次性把所有找到的字符串赋值给maAr
str += "at " + maAr.index + " xx "+ maAr[0] + "\n";        //exec每次赋值一个字符串给maAr,直接写maAr会报错,一定要写成maAr[0],这不是数组形式吗?
            }
alert(str);
0 回复
1