有一个block div,在他里面有一个未知数量的链接,如“a href onclick”,如果有多个链接,则用逗号和空格分隔。
var reg = /<div class="labeled fl_l"><a href="[^"]*" onclick="[^"]*">(.+?)<\/a>(, <a href="[^"]*" onclick="[^"]*">(.+?)<\/a>{1,})?<\/div>/mg;
var arr;
while ((arr = reg.exec(data)) != null) {
console.log(arr[0]); //contains the entire text (because it is java script)
console.log(arr[1]); //contains the name of the first link
console.log(arr[2]); //contains the following "a href" entirely (if I will point out (?: x, <a... /a>), then the nested brackets will not work)
console.log(arr[3]); //contains the name of the second link, **and then all of the code**
}
}
我认为应该使用它([^ <] *)
来代替(. +?)
,但它根本不起作用。