Created
January 20, 2014 08:05
-
-
Save karmiphuc/8516571 to your computer and use it in GitHub Desktop.
URL Parsing from text
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String.prototype.parseURL = function() { | |
return this.replace(/[A-Za-z]+:\/\/[A-Za-z0-9-_]+\.[A-Za-z0-9-_:%&~\?\/.=]+/g, function(url) { | |
return url.link(url); | |
}); | |
}; | |
String.prototype.parsePseudoURL = function() { | |
return this.replace(/(^| )([^\/])((www|[^\/\. ]+)\.[\S]+(\b|$|))/gim, '$1<a href="http://$2$3" target="_blank">$2$3</a>'); | |
}; | |
s = 'Tinhte.vn Đời có bao lâu mà hững hờ www.google.com.vn xxx google.com.vn xxx Tôi yêu Google http://google.com.vm/search/asdajs.html'; | |
s = s.parseURL().parsePseudoURL(); | |
alert(s); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment