As an alternative to regex, you can let the System.Uri class System.Uri the string for you. You just need to make sure the string contains the schema.
string uriString = "http://www.google.com/search"; if (!uriString.Contains(Uri.SchemeDelimiter)) { uriString = string.Concat(Uri.UriSchemeHttp, Uri.SchemeDelimiter, uriString); } string domain = new Uri(uriString).Host;
This solution also filters out any port numbers and translates IPv6 addresses to its canonical form.
Niels van der rest
source share