search match:
// search match
let str = "jiajia.com"
console.log(str.search("a"));//2 search匹配到返回所在的索引,没找到返回-1
console.log(str.match(/a/gi));//['a', 'a']
matchAll:
let url = `
http://www.sina.com.cn
https://jiajia.com
https://www.baidu.com
`;
let reg = /https?:\/\/(\w+\.)?(\w+\.)+(com|cn)/gi;
console.log(url.match(reg));//["http://www.sina.com.cn","https://jiajia.com","https://www.baidu.com"]
for (const iterator of url.matchAll(reg)) {
console.log(iterator);
}