DEV Community

Discussion on: Need help cleaning up this code, which modifies the subdomain.

Collapse
 
kspeakman profile image
Kasey Speakman • Edited
var subdomainMatch = /^[^.]+\./;
var admin = window.location.host.replace(subdomainMatch, "admin.");

This is using a regex, but at least it is a small one.

op meaning
^ line starts with
[^ any character except the following
. the character .
] end of character list
+ match one or more of the preceding (any character except .)
\. match the character .
Collapse
 
dechamp profile image
DeChamp • Edited

gorgeous! I love me some regex. I was trying to do this yesterday but going about it all wrong. I was trying to abstract out the last part of the domain. Should have made it easy on myself and just find/replace the subdomain! Thank you!