Received: from localhost (unknown [200.46.204.191]) by postgresql.org (Postfix) with ESMTP id 0A66A9F95E4 for ; Sun, 16 Sep 2007 20:19:05 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.191]) (amavisd-maia, port 10024) with ESMTP id 80217-07 for ; Sun, 16 Sep 2007 20:19:00 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from oxford.xeocode.com (unknown [87.127.95.196]) by postgresql.org (Postfix) with ESMTP id 067DF9F9D04 for ; Sun, 16 Sep 2007 20:19:00 -0300 (ADT) Received: from localhost ([127.0.0.1] helo=oxford.xeocode.com) by oxford.xeocode.com with esmtp (Exim 4.67) (envelope-from ) id 1IX3OD-0002pI-2b; Mon, 17 Sep 2007 00:18:57 +0100 To: "Paul Lambert" Cc: "sql pgsql" Subject: Re: Extracting hostname from URI column In-Reply-To: <46EDB43D.9060405@autoledgers.com.au> (Paul Lambert's message of "Mon\, 17 Sep 2007 06\:54\:53 +0800") User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.1 (gnu/linux) X-Draft-From: ("nnimap+mail01.enterprisedb.com:INBOX.sql" 1084) References: <335491.75226.qm@web54303.mail.re2.yahoo.com> <46E73D1C.4020009@autoledgers.com.au> <46EDB43D.9060405@autoledgers.com.au> From: Gregory Stark Organization: EnterpriseDB Date: Mon, 17 Sep 2007 00:18:56 +0100 Message-ID: <873axekxlr.fsf@oxford.xeocode.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200709/122 X-Sequence-Number: 29335 "Paul Lambert" writes: > What would be the best way to do something like that? I assume it won't be a > simple regex like the above due to the country codes on the end of some > domains. My thought is look at the last portion of the domain, if it's 2 > characters long then assume it's a country code and grab the last three > sections, if it's not three characters long then assume it's an international > domain and grab the last two... but that sounds a bit dodgy. Not all countries break up their national tld space into sections like .co.uk or .com.au. Canadian domains can be bought directly under .ca like amazon.ca. I think you'll have to store a specific list of tlds and how deep you want to look. -- Gregory Stark EnterpriseDB http://www.enterprisedb.com