如何检测并获取字符串javascript的url [英] how to detect and get url on string javascript
本文介绍了如何检测并获取字符串javascript的url的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何检测和获取字符串javascript上的网址?
how to detect and get url on string javascript?
示例:
var string = "hei dude, check this link http:://google.com and http:://youtube.com"
如何从我的字符串中得到这样的结果:
how to get result like this from my string :
var result = ["http:://google.com", "http:://youtube.com"]
那怎么办?
推荐答案
您输入的在 http
之后有两个 ::
.不确定是否有意.如果是这样,请使用:
You input has double ::
after http
. Not sure if it intentional. If it is then use:
var matches = string.match(/\bhttps?::\/\/\S+/gi);
如果只需要一个:
,则使用:
If only one :
is needed then use:
var matches = string.match(/\bhttps?:\/\/\S+/gi);
这篇关于如何检测并获取字符串javascript的url的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文