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