Re: Mixing greediness in regexp_matches

Поиск
Список
Период
Сортировка
От Daniel Verite
Тема Re: Mixing greediness in regexp_matches
Дата
Msg-id ed5241b7-b839-4cec-8c1f-b62245f464d6@manitou-mail.org
обсуждение исходный текст
Ответ на Re: Mixing greediness in regexp_matches  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-general
    Tom Lane wrote:

> I'd try forcing the match to be the whole string, ie
>
>         ^(.*?)(foo|bar|foobar)(.*)$
>
> which would also save some work for restarting the iteration,
> since you'd have already captured the all-the-rest substring.

In that case regexp_matches will return 0 or 1 row. In the
above-mentioned example, that would be:

=> select regexp_matches('the string has foo and foobar and bar and more',
 '^(.*?)(foo|foobar|bar)(.*)$', 'g');
             regexp_matches
--------------------------------------------------------
 {"the string has ",foo," and foobar and bar and more"}

So the next iteration would consist of calling regexp_matches()
on result[3], and so on until no match is found.
I think it would work as desired, but probably much less efficiently on
large strings/large number of matches than if a single call of
regexp_matches() could return all matches.


Best regards,
--
Daniel Vérité
PostgreSQL-powered mailer: http://www.manitou-mail.org
Twitter: @DanielVerite



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

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: Mixing greediness in regexp_matches
Следующее
От: "Daniel Verite"
Дата:
Сообщение: Re: Mixing greediness in regexp_matches