Re: regexp_matches problem

Поиск
Список
Период
Сортировка
От Albe Laurenz
Тема Re: regexp_matches problem
Дата
Msg-id D960CB61B694CF459DCFB4B0128514C202FF65C2@exadv11.host.magwien.gv.at
обсуждение исходный текст
Ответ на Re: regexp_matches problem  ("WP Perquin" <perquin@yuplounge.nl>)
Ответы Re: regexp_matches problem  ("WP Perquin" <perquin@yuplounge.nl>)
Список pgsql-general
WP Perquin wrote:
> When I make the following simplified example:
>
> SELECT regexp_matches('<img src="wwww" title="dit is een
> title tekst" class="class12">'
>
> ,'((title\s*=\s*\"([^"]*)")+)|((src\s*=\s*\"([^"]*)")+)','ig')
>
> My result are 2 rows:
>
> "{NULL,NULL,NULL,"src=\"wwww\"","src=\"wwww\"",wwww}"
>
> "{"title=\"dit is een title tekst\"","title=\"dit is een
> title tekst\"","dit is een title tekst",NULL,NULL,NULL}"
>
> I would like to have 1 row which contains both the records.
> Does anyone know how I can solve this?

Do you really want all those NULLs?

Is that what you want:

SELECT match[1]
FROM regexp_matches('<img src="wwww" title="dit is een title tekst" class="class12">',
                    '(title\s*=\s*\"[^"]*"|src\s*=\s*\"[^"]*")',
                    'ig') AS match;

This query returns two rows.

When you write that you want to have one row that contains both
records, do you mean:

a) one string that is the concatenation of both strings
or
b) one row that is a single array with two string elements

Whatever it is you want, you will probably need to write a
little aggregate function that does that for you, something like

CREATE FUNCTION text_cats(state text[], nextv text) RETURNS text[]
   IMMUTABLE STRICT LANGUAGE sql
   AS 'SELECT $1 || $2';

CREATE AGGREGATE text_cat(text) (
   SFUNC = text_cats,
   STYPE = text[],
   INITCOND = '{}' );

for variant b).

Then you can

SELECT text_cat(match[1])
FROM regexp_matches('<img src="wwww" title="dit is een title tekst" class="class12">',
                    '(title\s*=\s*\"[^"]*"|src\s*=\s*\"[^"]*")',
                    'ig') AS match;

Yours,
Laurenz Albe

В списке pgsql-general по дате отправления:

Предыдущее
От: Scott Marlowe
Дата:
Сообщение: Re: Cannot login for short period of time
Следующее
От: Henry
Дата:
Сообщение: Re: Cannot login for short period of time