2
我試圖在我通過Json響應循環時提取錨點的部分(URL,目標,文本)並且無法這樣做。javascript正則表達式從錨定標記中提取錨文本,URL和目標
我發現這個問題/答案,讓我95%的方式出現:
javascript regex to extract anchor text and URL from anchor tags
var input_content = "blah \
<a href=\"http://yahoo.com\">Yahoo</a> \
blah \
<a href=\"http://google.com\">Google</a> \
blah";
var matches = [];
input_content.replace(/[^<]*(<a href="([^"]+)">([^<]+)<\/a>)/g, function() {
matches.push(Array.prototype.slice.call(arguments, 1, 4));
});
alert(matches.join("\n"));
//Gives
//<a href="http://yahoo.com">Yahoo</a>,http://yahoo.com,Yahoo
//<a href="http://google.com">Google</a>,http://google.com,Google
我一直沒能修改上述正則表達式來獲取目標。任何幫助,將不勝感激。
謝謝。
我能夠利用jQuery,並做了這個訣竅,thx。 – Steve 2011-02-09 15:00:17