Received: from localhost (unknown [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id 61A649F95CE for ; Sun, 16 Sep 2007 19:56:53 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-maia, port 10024) with ESMTP id 16419-01 for ; Sun, 16 Sep 2007 19:56:42 -0300 (ADT) X-Greylist: whitelisted by SQLgrey-1.7.5 Received: from mail06.syd.optusnet.com.au (mail06.syd.optusnet.com.au [211.29.132.187]) by postgresql.org (Postfix) with ESMTP id A52789F95C0 for ; Sun, 16 Sep 2007 19:56:47 -0300 (ADT) Received: from [127.0.0.1] (online4-new.lnk.telstra.net [139.130.169.227]) (authenticated sender plengada@optusnet.com.au) by mail06.syd.optusnet.com.au (8.13.1/8.13.1) with ESMTP id l8GMudD5012014 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Mon, 17 Sep 2007 08:56:44 +1000 Message-ID: <46EDB43D.9060405@autoledgers.com.au> Date: Mon, 17 Sep 2007 06:54:53 +0800 From: Paul Lambert User-Agent: Thunderbird 2.0.0.6 (Windows/20070728) MIME-Version: 1.0 To: sql pgsql Subject: Re: Extracting hostname from URI column References: <335491.75226.qm@web54303.mail.re2.yahoo.com> <46E73D1C.4020009@autoledgers.com.au> In-Reply-To: <46E73D1C.4020009@autoledgers.com.au> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200709/121 X-Sequence-Number: 29334 Paul Lambert wrote: > chester c young wrote: >>> I'm trying to use substr() and position() functions to extract the >>> full host name (and later a domain) from a column that holds URLs. >> >> substring( href from '.*://\([^/]*)' ); >> > > Ok, your solution looks better than mine... but I have no idea how to > interpret that, time to consult some manuals. > OK - following on from this, I'm doing a similar thing to the OP to analyze my proxy's traffic (never occured to me to do it in a db until that post) I've done the above regex to pull out the domain part of the URL and am left with results such as: "acvs.mediaonenetwork.net" "profile.ak.facebook.com" "www.bankwest.com.au" What I want to do next is pull out the major domain part of the URL I.e. for the above three records I should end up with "mediaonenetwork.net" "facebook.com" "bankwest.com.au" 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. -- Paul Lambert Database Administrator AutoLedgers