Heads up! This post was written 14 years ago. Some information might be outdated or may have changed since then.
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 '' + nice + '';
} else {
url = nice.replace(/^www./i, '');
return '' + url + '';
}
});
return text;
} Пример:
text = text.parseURL();