Re: Inside the Regex Engine - Mailing list pgsql-hackers

From Alvaro Herrera
Subject Re: Inside the Regex Engine
Date
Msg-id 20031203033842.GB4813@dcc.uchile.cl
Whole thread Raw
In response to Inside the Regex Engine  (david@fetter.org (David Fetter))
List 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)


pgsql-hackers by date:

Previous
From: greg@turnstep.com
Date:
Subject: Re: ALTER SEQUENCE enchancement
Next
From: Tom Lane
Date:
Subject: Re: Inside the Regex Engine