Using a regex to determine domain using JavaScript
Posted
by jerome
on Stack Overflow
See other posts from Stack Overflow
or by jerome
Published on 2009-05-08T19:21:04Z
Indexed on
2010/04/25
8:03 UTC
Read the original article
Hit count: 394
JavaScript
|regex
Hi All,
If, as here at work, we have test, staging and production environments, such as:
http://staging.my-happy-work.com
I am writing some javascript that will redirect the browser to a url such as:
http://[environment].my-happy-work.com/my-happy-video
I need to be able to determine the current environment that we are in.
There is the possibility that I will currently be at a url such as:
http://[environment].my-happy-work.com/my-happy-path/my-happy-resource
I want to be able to grab the window.location but strip it of everything but:
http://[environment].my-happy-work.com
And then append to that string + "/" + "my-happy-video".
I am not skilled with regex, but I suppose there would be a way to parse the window.location up to the ".com"
Thoughts? Thanks!
© Stack Overflow or respective owner