var str ="cat matt daa bat"
var re = /at+/g;
var match = str.match(re);
console.log(match);
console.log(new RegExp(re).exec(str));
输出如下
[ 'at', 'att', 'at' ]
[ 'at', index: 1, input: 'cat matt daa bat' ]
[Finished in 0.5s]
var str ="cat matt daa bat"
var re = /at+/g;
var match = str.match(re);
console.log(match);
console.log(new RegExp(re).exec(str));
输出如下
[ 'at', 'att', 'at' ]
[ 'at', index: 1, input: 'cat matt daa bat' ]
[Finished in 0.5s]