使用JavaScript对文本中的正则表达式和检测URL进行Urlify

时间:2016-06-07 07:31:51

标签: javascript angularjs regex url

大家好

现在对我有用的只是链接(www&& http),链接如:https://www.facebook.com/ - 此类链接对我不起作用。

这是代码:

   $scope.urlify=function(text){

        var urlRegex = /(https?:\/\/[^\s]+)|(www[^\s]+)/g;   

        return text
            .replace(urlRegex, function(url) {
                return '<a href="http://' + url + '" target = "_blank">' + url + '</a>';    
            }).replace("http://http://", "http://");
      }//urlify function

enter image description here

我需要更改代码? 非常感谢。

0 个答案:

没有答案