From: Mr zengr Date: 2010-08-20T15:02:56+09:00 Subject: Re: Extract domain name Charles Calvert wrote: > All, > > I have the same basic issue as discussed in this thread last year: > . > > Justin Collins points out the greatest difficulty with the situation, > i.e. that when dealing with a country code TLD, one may well have a > different number of parts (e.g. example.co.uk) than when dealing with > a gTLD (example.com). > > The only solution that has occurred to me is to have a list of known > TLDs and second level domains (e.g. co.uk) that are insufficiently > specific, requiring a subdomain for additional specificity. The > problem is that this requires maintenance as well as initial research. > > Does anyone have any suggestions for an alternative method to solve > this problem? I'm currently using Addressable:URI > (http://addressable.rubyforge.org/api/classes/Addressable/URI.html) to > parse the URLs and extract the host names. I think the best way will be actually match with a list of TLDs and gTLDs. Mozilla has a list of domains: http://mxr.mozilla.org/mozilla/source/netwerk/dns/src/effective_tld_names.dat A stackoverflow question on the same topic: http://stackoverflow.com/questions/569137/how-to-get-domain-name-from-url Their solution is regex. -- Posted via http://www.ruby-forum.com/.