Regex for hostname

I have the following code:
if (currHost.match(/(alpha|beta|test|dev|load|local)\./)) {

Open in new window

but I need to add additional conditions such as "file:" , ".od*." (* is wildcard), "dev-wa." and ".hbox."  not sure how to approach this?
894359Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

käµfm³d 👽Commented:
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.
0
894359Author Commented:
Capturing the URL (without query string) via
 var currHost = location.protocol+"//"+location.hostname+location.pathname;

Open in new window

and want to filter out non-production urls coming for our analytics code. So we could have something with
 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
0
894359Author Commented:
Anybody out there? Where's emoticons when you need them!!!
0
Terry WoodsIT GuruCommented:
Something like this?:

 var currHost = location.protocol+"//"+location.hostname+location.pathname;
                                            
if (currHost.match(/file:\/\/|dev-wa\.mydomain\.com|www\.(sq[ca]|od[dp]|hbox)\.mydomain\.com|((alpha|beta|test|dev|load|local)\.)/)) {

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
894359Author Commented:
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:')) {

Open in new window

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.