url replace javascript code example
Example 1: window replace url
location.replace("url");
Example 2: javascript url replace
function URLReplacer(str){
let match = str.match(/(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig);
let final=str;
match.map(url=>{
final=final.replace(url,"<a href=\""+url+"\" target=\"_BLANK\">"+url+"</a>")
})
return final;
}