Converting a URL into an Active Link in JavaScript

Pass in some text and get it back with the URLs converted into clickable links

function linkify(text){
if (text) {
text = text.replace(
/((https?\:\/\/)|(www\.))(\S+)(\w{2,4})(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/gi,
function(url){
var full_url = url;
if (!full_url.match('^https?:\/\/')) {
full_url = 'http://' + full_url;
}
return '' + url + '';
}
);
}
return text;
}

About Keiron

Web Developer based in the UK. Click here if you want to work with me