将一个符合URL格式的字符串变成链接

 
function replaceURLWithHTMLLinks(text) {
      /*
        Example:

            >>> GateOne.Utils.replaceURLWithHTMLLinks('Downloading http://foo.bar.com/some/file.zip');
            "Downloading http://foo.bar.com/some/file.zip"
        */
        var exp = /((https?|ftp|file)://[-A-Z0-9+&@#/%?=~_|!:,.;]*[-A-Z0-9+&@#/%=~_|])/ig;
        return text.replace(exp,"$1");
    }
原文地址:https://www.cnblogs.com/rubylouvre/p/3480013.html