I need a regexp to strip out just the domain name part of a url. So for example if i had the following url:
http://www.website-2000.com
the bit I\'d want the
This one allows you not to have to worry about any of the http/https/ftp etc... in front and also captures all your subdomains too.
(?:www\.)?([a-z0-9\-.]+)(?:\.[a-z\.]+[\/]?).*/i
The only times it fails that I've found are: - If a . precedes the domain/subdomain without any text before it, the . is included in the regex capture. - Emails with . in them will not work. (fix this by checking passed domain first for the @ symbol before running through regex) - Whitespace in the middle of the domain/subdomain