Ruby's Louvre

每天学习一点点算法

导航

将一个符合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 = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig;
        return text.replace(exp,"$1");
    }

posted on 2013-12-18 11:50  司徒正美  阅读(1891)  评论(1编辑  收藏  举报