MJ
asked on
Regex for hostname
I have the following code:
if (currHost.match(/(alpha|beta|test|dev|load|local)\./)) {
but I need to add additional conditions such as "file:" , ".od*." (* is wildcard), "dev-wa." and ".hbox." not sure how to approach this?
Your current regex will match those various words if they occur *anywhere* in the string contained within currHost. Your inclusion of "file:" seems to imply that you want to include a scheme as well. Is this correct? If you can clarify what "things" you want to be matched, then we can appropriately place them in your regex.
ASKER
Capturing the URL (without query string) via
file://
www.sqc.mydomain.com
www.sqa.mydomain.com
www.odd.mydomain.com
www.odp.mydomain.com
www.hbox.mydomain.com
dev-wa.mydomain.com
etc
var currHost = location.protocol+"//"+location.hostname+location.pathname;
and want to filter out non-production urls coming for our analytics code. So we could have something withfile://
www.sqc.mydomain.com
www.sqa.mydomain.com
www.odd.mydomain.com
www.odp.mydomain.com
www.hbox.mydomain.com
dev-wa.mydomain.com
etc
ASKER
Anybody out there? Where's emoticons when you need them!!!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Below is the solution:
if ((currHost[i].match(/(alpha|beta|test|dev|load|local|phi|\.stage|\.stg|\.it.{1}|\.od.{1}|dev-wa|\.sq.{1}|\.hbox)\./))||(document.location.protocol === 'file:')) {