Re: Inside the Regex Engine

From: Alvaro Herrera <alvherre(at)dcc(dot)uchile(dot)cl>
To: David Fetter <david(at)fetter(dot)org>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Inside the Regex Engine
Date: 2003-12-03 03:38:42
Message-ID: 20031203033842.GB4813@dcc.uchile.cl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Tue, Dec 02, 2003 at 07:52:57PM -0600, David Fetter wrote:

> As a perl weenie, I'm used to being able to do things with regexes
> like
>
> $text =~ s/(foo|bar|baz)/NO UNIX WEENIES HERE/;
> $got_it = $1;
>
> While PL/Perl is great, it's not available everywhere, and I'd like to
> be able to grab atoms from a regex match in, say, a SELECT. Is there
> some way to get access to them?

Huh, the best I am able to do is

alvh=> select substring('bazfoo fubar', 'fu(foo|bar)');
substring
-----------
bar
(1 fila)

The choice of the name for the function seems weird to me. Also note
that you are able to use only one set of parenthesis (i.e. the first
gets picked up, the rest is ignored).

If you need to be able to extract further things, there's a tip in the
docuemntation that reads

"If you have pattern matching needs that go beyond this, consider
writing a user-defined function in Perl or Tcl."

It does not appear to be that difficult to add the functionality needed
to extract random atoms, but there's some hacking involved.

--
Alvaro Herrera (<alvherre[a]dcc.uchile.cl>)
"Cuando no hay humildad las personas se degradan" (A. Christie)

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2003-12-03 04:05:42 Re: Inside the Regex Engine
Previous Message greg 2003-12-03 03:17:09 Re: ALTER SEQUENCE enchancement