如何让RegEx获取整个URL..从http开始,获取后面的所有内容,直到出现空白以及如何排除某些字符
How do I get RegEx to get the entire URL... start at http and get everything after until a whitespace and how to exclude certain characters
好吧,我有一个asp文件,它将推特上的rss提要拉到我的服务器上,我使用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++
});
这就是我目前所拥有的:
这是示例tweet(原始字符串(:
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,直到成为空白字符,同时排除逗号等。
这个正则表达式应该能完成任务:'s*(?i)href's*='s*('"([^"]*'")|'[^']*'|([^'">'s]+))
。
示例:http://regex101.com/r/eL3wV4
或者,如果您没有内联,a href:(http:[^'s]*)|(https[^'s]*)
应该只为您提供http://*
或https://*
。
示例:http://regex101.com/r/uE5bZ5
好的,这是这个问题的答案,但https://stackoverflow.com/users/1472389/damien-overeem@Damian Overeem应该为向我展示regex101而获得所有赞誉,但以下是我如何选择我想要的:
$href = $desc.match(/'b(http|https)?(:'/'/)?('S*)'.('w{2,4}('S*))'b/ig);
在这里查看http://regex101.com/r/gT6hC2
相关文章:
- 使用 jQuery 的 .on 函数如何获取事件的原始元素
- jquery试图按名称获取按钮位置
- 如何在jQuery中获取元素的形式
- 如何在php文件中获取$.post-ajax传递的值
- 在Shopify中获取博客文章的图片
- 获取当前URL,替换部分路径名,然后在空白选项卡中打开
- 获取空白抓取数据
- 使用obj.style.marginTop获取页边空白顶部失败,但如果首先显式设置了marginTop,则该操作有效
- 使用RequireJS和Grunt获取空白页面
- 从一行开始直到任何内容,获取除新行之外的所有空白
- 使用JavaScript获取页边空白
- Maelstorm jquery xmlrpc获取空白错误
- Regex获取字符和空白之间的字符串,并排除第一个分隔符
- 如何让RegEx获取整个URL..从http开始,获取后面的所有内容,直到出现空白以及如何排除某些字符
- Servlet偶尔会从Javascript XHR获取空白数据
- 如何在php中使用jquery在对话框中获取文本框的值,我将其作为空白或未定义
- 获取一个空白输入字段的ID
- Javascript幻灯片问题.正在获取空白屏幕
- 为什么我的函数没有从空白输入框中获取值并正确执行函数
- 空白屏幕和必要的滚动事件,以在Sencha Touch中记录较少的商店中获取值