From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | "Daniel Verite" <daniel(at)manitou-mail(dot)org> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: Mixing greediness in regexp_matches |
Date: | 2019-12-23 15:26:15 |
Message-ID: | 29225.1577114775@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
"Daniel Verite" <daniel(at)manitou-mail(dot)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
From | Date | Subject | |
---|---|---|---|
Next Message | Daniel Verite | 2019-12-23 15:58:47 | Re: Mixing greediness in regexp_matches |
Previous Message | Tom Lane | 2019-12-23 15:15:40 | Re: Mixing greediness in regexp_matches |