DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

String.prototype.tld – Match Top-Level-Domain

08.12.2008
| 5596 views |
  • submit to reddit
        // javascript : match tld in window.location.hostname (last 2-6 chars)
String.prototype.tld = function(){
	return (m = this.match(new RegExp("\.([a-z,A-Z]{2,6})$") )) ? m[1] : false;
}