"Daniel Verite" writes:
> FWIW, in plperl, there's a simple solution:
> $string =~ s/(foobar|foo|...)/$replace{$1}/g
Well, our manual does suggest using plperl (or pltcl) when the
built-in pattern match functions aren't adequate ;-)
regards, tom lane
Tom Lane wrote:
> 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 posi
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
"Daniel Verite" 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
"Daniel Verite" 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 n
Hi,
When looking into how to implement a global replace of multiple
substrings (each with their own replacement) in sql
or plpgsql, I'm wondering if/how an RE with an alternation
can be used.
The basic idea is to iterate on the rows produced by
regexp_matches(string, '(.*?)(foo|bar|foobar)'