正则表达式 - 查找推文中的所有链接 [英] Regex - find all links in a tweet
问题描述
我的正则表达式很差,让我失望,所以在这里提供一些帮助会很棒.
My regex is poor and letting me down so some help would be great here.
我想要做的就是返回出现在推文中的所有链接(只是一个字符串)——一些例子是:
All I want to do is return all the links which appear in a tweet (just a string) - Some examples are:
"很棒的总结 http://mytest.com/blog/post.html (#test)
"http://mytest.com/blog/post.html (#test)
帖子:http://mytest.com/blog/post.html"
它还应该支持多个链接,例如:阅读 http://mytest.com/blog/post.html 和 http://mytest.com/blog/post_two.html"
It should also support multiple links like:
"read http://mytest.com/blog/post.html and http://mytest.com/blog/post_two.html"
任何帮助都会很棒!
谢谢
本
推荐答案
试试这个:
/\bhttps?:\/\/\S+\b/
更新:
捕捉以www"开头的链接.也是(没有http://"前缀),你可以试试这个:
To catch links beginning with "www." too (no "http://" prefix), you could try this:
/\b(?:https?:\/\/|www\.)\S+\b/
这篇关于正则表达式 - 查找推文中的所有链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!