var inputString = `
var i=0;
urls[i]='/art/2024/11/16/art_52181_2908919.html';
headers[i]="• 10个;
imgstrs[i]=' ';
i++;
urls[i]='/art/2024/10/31/art_52181_2908886.html';
headers[i]="• ;
imgstrs[i]=' ';
i++;
urls[i]='/art/2024/10/30/art_52181_2908880.html';
headers[i]="•;
imgstrs[i]=' ';
i++;
urls[i]='/art/2024/10/25/art_52181_2908870.html';
headers[i]="
`;
// 正则表达式,用于匹配 urls[i] 赋值中的 URL
var regex = /urls\[i\].*'/g;
var matches;
var urlsArray = [];
// 使用全局正则表达式的 exec 方法遍历所有匹配项
while ((matches = regex.exec(inputString)) !== null) {
// matches[1] 是捕获组中的内容,即 URL
urlsArray.push(matches[0].replace(/urls\[i\]='|'/g, ''));
}
// 输出结果
console.log(urlsArray);
console