Last active
October 10, 2018 11:55
-
-
Save pgilad/9660929 to your computer and use it in GitHub Desktop.
Regex for matching subdomains in document.location.hostname
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
var getSubdomain = function (baseDomain) { | |
if (!baseDomain) { | |
return null; | |
} | |
var regSub = new RegExp('^((?!' + baseDomain + '|www)([^.]*))', 'g'); | |
var _subdomain = document.location.hostname.match(regSub); | |
if (_subdomain && _subdomain[0]) { | |
return _subdomain[0]; | |
} else { | |
return null; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment