regex back-references? - Mailing list pgsql-general

From Michael Blakeley
Subject regex back-references?
Date
Msg-id p05000e27b5c60c814e15@blakeley.com
Whole thread Raw
Responses Re: regex back-references?  (Tom Lane <tgl@sss.pgh.pa.us>)
List 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

pgsql-general by date:

Previous
From: Marc Roos
Date:
Subject: datatype SET
Next
From: "Chris Knight"
Date:
Subject: Memory Leaks in plpgsql in 7.0.2