regex back-references?

From: Michael Blakeley <mike(at)blakeley(dot)com>
To: pgsql-general(at)postgreSQL(dot)org
Subject: regex back-references?
Date: 2000-08-20 22:39:36
Message-ID: p05000e27b5c60c814e15@blakeley.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Does postgresql support regex back-references? In case the term isn't
standard, what I'd like to do is match a string like
SELECT 'http://www.blakeley.com/foo/bar/biz.html'::text ~
'^http://.*([^\.]+\.[^\.]+)/?'::text;
except that I'm only interested in the part inside the parenthesis
(in case it's not obvious, I'm trying to extract the domain.tld, eg
"blakeley.com"). With Perl, one does this with code like:
$u = 'http://www.blakeley.com/foo/bar/biz.html';
if ($u =~ '^http://.*([^\.]+\.[^\.]+)/?') {
print "domain: $1\n";
}

Is this sort of thing supported in postgres?

Or is there another way to solve the problem? I got pretty close with:

SELECT trim(leading 'www.' from substring(url from 8 for
position('/' in trim(leading 'http://' from url))-1)) ...

but it's not quite right, since I want to to trim any hostname and
subdomains off of the URL (not just 'www.').

thanks,
-- Mike

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Chris Knight 2000-08-21 05:03:07 Memory Leaks in plpgsql in 7.0.2
Previous Message Marc Roos 2000-08-20 11:57:29 datatype SET