I need to check if my server is on the live or development mode. Currently I am doing it like this:
<cfset isLive = FindNoCase("www.mydomain.com",CGI.SERVER_NAME) NEQ 0>
But the above does not seem foolproof. If the user tries
.. it will not work properly. Can anyone tell me how to accomplish this with a regex?
Turn it around and check for the dev mode instead of live. That will give you less options to struggle with. This solution is not foolproof either.
I would recommend:
<cfset isLive = ReFindNoCase("^(www\.)?mydomain\.com$",CGI.SERVER_NAME) NEQ 0>
The good news is that CGI.SERVER_NAME only includes the domain name used to access the site - not the protocol information (even on HTTPS), so you don't have to worry about that.
I'm guessing from your examples that if the site is accessed using "www" prefix or no prefix that it should be the live site and all other prefixes - or any other domain name - will indicate the dev site.
This would mean that if you ever need another domain prefix on the live site for any reason that this would return false.
Here is how to change it if you needed the "bob" prefix on the live site:
<cfset isLive = ReFindNoCase("^(((www)|(bob))\.)?mydomain\.com$",CGI.SERVER_NAME) NEQ 0>
You could also go the other way and look for something like "test" or "dev" anywhere in the domain name to establish that it is a test site:
<cfset isTest = ReFindNoCase("\b((test)|(dev))\b",CGI.SERVER_NAME) NEQ 0>