分别运行一下两段代码 求[[[[[[[[[[[[[[[[[[[[[[[[[@robbin](/user/robbin)](/user/robbin)](/user/robbin)](/user/robbin)](/user/robbin)](/user/robbin)](/user/robbin)](/user/robbin)](/user/robbin)](/user/robbin)](/user/robbin)](/user/robbin)](/user/robbin)](/user/robbin)](/user/robbin)](/user/robbin)](/user/robbin)](/user/robbin)](/user/robbin)](/user/robbin)](/user/robbin)](/user/robbin)](/user/robbin)](/user/robbin)](/user/robbin) 大神指点一二 运行第一段代码没有任何问题, 但是第二段代码运行的时候则会死掉,如果不及时关掉的话有可能会导致死机 代码运行版本 8.20 (node到处是坑啊)
function test(){
var reg = /href=['"](.+?)['"]/gim;
var str = '<link rel="stylesheet" type="text/ss" href="/c4.css" />';
var result = reg.exec(str);
while(result){
console.log(result[1]);
result = reg.exec(str);
}
}
test();
下面的代码之比上边的代码少了一个g
function test(){
var reg = /href=['"](.+?)['"]/im;
var str = '<link rel="stylesheet" type="text/ss" href="/c4.css" />';
var result = reg.exec(str);
while(result){
console.log(result[1]);
result = reg.exec(str);
}
}
test();
8 回复