-4
function urllinks(str){
    return str.replace(/\b((http|https):\/\/\S+)/g,'<a href="$1" target="_blank">$1</a>');
}

This code is replacing only "http" and "https" texts... but it doesn't replace texts that begins with "www"...

Schito
  • 27
  • 4

1 Answers1

1

I didn't tried it

function urllinks(str){
    str = str.replace(/\b(www\.\S+)/g,'http://$1');
    return str.replace(/\b((http|https):\/\/\S+)/g,'<a href="$1" target="_blank">$1</a>');
}
haltabush
  • 4,508
  • 2
  • 24
  • 41