我想解析html字符串中的所有链接,如下所示:
<a href="javascript:makePopup('match_stats_popup.php?matchID=185934701')">Match Stats</a>
<a href="javascript:makePopup('http://www.atpworldtour.com/Share/Match-Facts-Pop-Up.aspx?t=416&y=2014&r=5&p=D643')">Match Stats</a>
预期输出是一系列链接:
['match_stats_popup.php?matchID=185934701',
'http://www.atpworldtour.com/Share/Match-Facts-Pop-Up.aspx?t=416&y=2014&r=5&p=D643']
我已创建此功能但在到达&#34;:
时不会停止function parseMatchStatsLinks(html) {
var regex = /href="javascript:makePopup\('(.*)'\)"/g;
var match = [];
var links = [];
while (match = regex.exec(html)) {
links.push(match[1]);
}
return links;
}
答案 0 :(得分:0)
我必须添加?
才能使其变得非贪婪:
href="javascript:makePopup\('(.*?)'\)"