Javascript стринг към url
0
- 14.06.2011 (Вторник)
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();
