从给定字符串中提取URL

时间:2013-07-12 14:37:28

标签: javascript regex

house home go https://www.monstermmorpg.com
nice hospital http://www.monstermmorpg.com 
this is incorrect url http://www.monstermmorpg.commerged 
continue

我想提取所有以http / https

开头的网址

我尝试使用这个正则表达式,但我什么都没得到。

$('links').value = stringText.match("\b(?:http://|https://)\S+\b/");

1 个答案:

答案 0 :(得分:1)

    var string = "house home go https://www.monstermmorpg.com hospital "
     +" http://www.monstermmorpg.io"
     +" this is incorrect url http://www.monstermmorpg.commerged"
    .match(/\b(https?:\/\/.*?\.[a-z]{2,4}\b)/g);

//只有前两个。

   ["https://www.monstermmorpg.com", "http://www.monstermmorpg.io"]