Re: select all matches for a regular expression ?

From: "ksherlock(at)gmail(dot)com" <ksherlock(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: select all matches for a regular expression ?
Date: 2007-02-24 02:02:14
Message-ID: 1172282534.809921.68290@k78g2000cwa.googlegroups.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I'm going to disagree and say it can be done (maybe).

Use regexp_replace() to convert non-numeric characters. Depending on
your final needs, you could leave it as a comma-separated list or
split it to an array.

select string_to_array(regexp_replace(regexp_replace('hello4 is 4 very
n1ce num8er', '[^0-9]+', ',', 'g'), '^,|,$', '', 'g'),',');

{4,4,1,8}

On Feb 23, 10:18 am, melser(dot)an(dot)(dot)(dot)(at)gmail(dot)com ("Anton Melser") wrote:
> On 23/02/07, Tom Lane <t(dot)(dot)(dot)(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>
> > "Anton Melser" <melser(dot)an(dot)(dot)(dot)(at)gmail(dot)com> writes:
> > > I need to be able to get all the matches for a particular regexp from
> > > a text field that I need to use in another query in a function. Is
> > > this possible with plpgsql? Do I have to install the perl language?
>
> > You need plperl (or pltcl; likely plpython would work too) --- the
> > built-in regex functions don't have any way to return more than the
> > first match. There's a patch pending to provide more functionality
> > here for 8.3, but it won't help you today.
>
> Thanks for the info
> Cheers
> Anton
>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Have you searched our list archives?
>
> http://archives.postgresql.org/

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Martin Winsler 2007-02-24 02:35:45 General Ledger db design
Previous Message CAJ CAJ 2007-02-24 01:41:00 Re: [HACKERS] urgent: upgraded to 8.2, getting kernel panics