Javascript String addLinkToHttpString()

Description

Javascript String addLinkToHttpString()





String.prototype.addLinkToHttpString = function(){
        var reg = /(http:\/\/|https:\/\/)((\w|=|\?|\.|\/|&|;|-)+)/g;
        return this.replace(reg, '<a href="$1$2">$1$2</a>');
};

var str = "adsf asdf https://github.com/";
console.log(str.addLinkToHttpString());//from w w  w . j a  v  a2 s . co m



PreviousNext

Related