Re: Mixing greediness in regexp_matches - Mailing list pgsql-general

From Daniel Verite
Subject Re: Mixing greediness in regexp_matches
Date
Msg-id ed5241b7-b839-4cec-8c1f-b62245f464d6@manitou-mail.org
Whole thread Raw
In response to Re: Mixing greediness in regexp_matches  (Tom Lane <tgl@sss.pgh.pa.us>)
List 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 by date:

Previous
From: Tom Lane
Date:
Subject: Re: Mixing greediness in regexp_matches
Next
From: "Daniel Verite"
Date:
Subject: Re: Mixing greediness in regexp_matches