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