Re: REGEXP_REPLACE woes - Mailing list pgsql-general

From Leif B. Kristensen
Subject Re: REGEXP_REPLACE woes
Date
Msg-id 200806101610.58085.leif@solumslekt.org
Whole thread Raw
In response to REGEXP_REPLACE woes  ("Leif B. Kristensen" <leif@solumslekt.org>)
List pgsql-general
On Tuesday 10. June 2008, CaT wrote:
>On Tue, Jun 10, 2008 at 03:43:02PM +0200, Leif B. Kristensen wrote:
>> On Tuesday 10. June 2008, Leif B. Kristensen wrote:
>> >Hey, I told it not to be greedy, didn't I?
>>
>> Found it. I must make *both* atoms non-greedy:
>
>That makes no sense. Take this bit of perl, which works as expected:
>
>$str = '[p=123|John Smith] and [p=456|Jane Doe]';
>
>print "before: '$str'\n";
>
>$str =~ s#\[p=(\d+)\|(.+?)\]#1 = $1, 2 = $2 rest of str = #;
>
>print "after: '$str'\n";
>
>There's a bug in your version of pcre I think as postgres would have
>little to do with the regex itself (I be guessing).

I found this obscure reference in the Pg docs
<http://www.postgresql.org/docs/8.2/interactive/functions-matching.html>

"In short, when an RE contains both greedy and non-greedy
subexpressions, the total match length is either as long as possible or
as short as possible, according to the attribute assigned to the whole
RE. The attributes assigned to the subexpressions only affect how much
of that match they are allowed to "eat" relative to each other."

And it was what made me try the above approach. I agree that it doesn't
make much sense.
--
Leif Biberg Kristensen | Registered Linux User #338009
http://solumslekt.org/ | Cruising with Gentoo/KDE
My Jazz Jukebox: http://www.last.fm/user/leifbk/

pgsql-general by date:

Previous
From: Michael Fuhr
Date:
Subject: Re: REGEXP_REPLACE woes
Next
From: Adrian Klaver
Date:
Subject: Re: Re: Accessing other databases with DBLink when leaving user/password empty