Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

javascript replace url on sentence as achor

    var url_replacer = function (str) {
        let match = str.match(/((https?|ftp|file)://[-A-Z0-9+&@#/%?=~_|!:,.;]*[-A-Z0-9+&@#/%=~_|])/ig);
        let final = str;
        if (match) { /// if nulled
            match.map(url => {
                final = final.replace(url, "<a href="" + url + "" target="_BLANK">" + url + "</a>");
            });
            return final;
        }else{
            return str;
        }
    };
 
PREVIOUS NEXT
Tagged: #javascript #replace #url #sentence #achor
ADD COMMENT
Topic
Name
9+2 =