簡體   English   中英

多次捕獲圖案

[英]Capturing a pattern multiple times

我想解析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']

我已經創建了此函數,但是到達“:

function parseMatchStatsLinks(html) {
    var regex = /href="javascript:makePopup\('(.*)'\)"/g;
    var match = [];
    var links = [];

    while (match = regex.exec(html)) {
        links.push(match[1]);
    }

    return links;
}

我必須添加? 使它不貪心:

 href="javascript:makePopup\('(.*?)'\)"

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM