Re: Mixing greediness in regexp_matches

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Mixing greediness in regexp_matches
Дата
Msg-id 29225.1577114775@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: Mixing greediness in regexp_matches  (Tom Lane <tgl@sss.pgh.pa.us>)
Ответы Re: Mixing greediness in regexp_matches
Список pgsql-general
"Daniel Verite" <daniel@manitou-mail.org> writes:
>> The basic idea is to iterate on the rows produced by
>> regexp_matches(string, '(.*?)(foo|bar|foobar)', 'g')
>> to break down the string into pairs of (non-matching segment,
>> matching segment) so that a final result can be assembled
>> from that (setting aside the last non-matching segment, that
>> can be retrieved in a final step).

BTW, just to think outside the box a bit, I wonder whether you
couldn't build this out of regexp_split_to_array:

regression=# select regexp_split_to_array('junkfoolbarfoolishfoobarmore', 'foo|bar|foobar');
 regexp_split_to_array
-----------------------
 {junk,l,"",lish,more}
(1 row)

The idea would be to iterate over the array elements, tracking the
corresponding position in the source string, and re-discovering at
each break which of the original alternatives must've matched.

It's sort of annoying that we don't have a simple "regexp_location"
function that would give you back the starting position of the
first match.

            regards, tom lane



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

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