regex back-references?

Поиск
Список
Период
Сортировка
От Michael Blakeley
Тема regex back-references?
Дата
Msg-id p05000e27b5c60c814e15@blakeley.com
обсуждение исходный текст
Ответы Re: regex back-references?  (Tom Lane <tgl@sss.pgh.pa.us>)
Список 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 по дате отправления:

Предыдущее
От: Marc Roos
Дата:
Сообщение: datatype SET
Следующее
От: "Chris Knight"
Дата:
Сообщение: Memory Leaks in plpgsql in 7.0.2