好的,我有一个 asp 文件将一个 rss 提要从 twitter 拉到我的服务器上,我使用 AJAX 分解每个条目并编写 HTML。我希望能够从条目的描述部分中提取链接,但我无法正确编写 RegEx。
$(entry).find('item').each(function() {
// gets the "id", "title", and "url" of current child element
$elm = $(this);
$title = $elm.find('title').text();
$desc = $elm.find('description').text();
$pubDate = $elm.find('pubDate').text();
$guid = $elm.find('guid').text();
$link = $elm.find('link').text();
$div.append('<div class="section" id="entry'+$count+'"><h3 class="pubDate">'+$pubDate.slice(0, -6)+'</h3><h3 class="desc">'+$desc+'</h3><div class="linkBox"><a href="'+$link+'" title="'+$title+'" class="link">'+$link+'</a></div></div>');
$href = $desc.match(/\b(http|https)?(:\/\/)?(\S*)\.(\w{2,4})\b/ig);
alert($href);
$count++
});
这是我到目前为止所拥有的:
这是示例推文(原始字符串):
I'm at Harrah's Hotel and Casino: Luxury Suite (New Orleans, LA) w/ 2 others http://t.co/UjxTIdiJ
我想使用以下方法提取链接:
$desc.match(/\b(http|https)?(:\/\/)?(\S*)\.(\w{2,4})\b/ig);
但它只返回:
http://t.co
我正在努力让所有字符都通过 http 直到出现空格字符,同时排除逗号等...