String.prototype.parseURL = function() {
text = this;
if (!text) {
return text;
}
text = text.replace(/((https?\:\/\/|ftp\:\/\/)|(www\.))(\S+)(\w{2,4})(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/gi, function(url) {
nice = url;
if (url.match('^https?:\/\/')) {
nice = nice.replace(/^https?:\/\//i, '');
return '<a class="external_link" target="_top" href="' + url + '">' + nice + '</a>';
} else {
url = nice.replace(/^www./i, '');
return '<a class="external_link" target="_top" href="' + url + '">' + url + '</a>';
}
});
return text;
} Пример:
text = text.parseURL();