
September 13th, 2009, 04:26 PM
|
 |
Contributing User
|
|
Join Date: Jul 2001
Location: England
Posts: 967
 
Time spent in forums: 20 h 32 m 5 sec
Reputation Power: 12
|
|
|
I'm a little rusty with my regex and there might be something simpler you could use, but try:
/(([a-z0-9]+)(-[a-z0-9]+)?)(\.[a-z]{2}\.[a-z]{2}|\.[a-z]{2,4})$/i
Also, AFAIK, domain names don't typically include underscores. You're out of luck if you're trying to match ip addresses with this expression, or if the user ends the domain with / or whatever. I don't really know where you're getting your data from, though, so it's difficult to say whether or not this will be a problem for you.
I tried this against the following (some of which are random domains, some real), and the expression worked out against all of them:
domain.name
domain.com
domain.ch
domain.co.uk
domain-name.com
my-domain-name.com
123-reg.co.uk
www.123-reg.co.uk
ab.com
my.really.obscure.domain.com
http://www.google.com
|