Re: [GENERAL] REGEXP_REPLACE woes

2008-06-11 Thread Leif B. Kristensen
On Wednesday 11. June 2008, Leif B. Kristensen wrote: >p := BTRIM(tmp, '#')::INTEGER; >name := get_person_name(p); >str := REPLACE(str, tmp, name); I did some "folding" and replaced the above with str := REPLACE(str, tmp, get_person_name(BTRIM(tmp, '#')::INTEGER)); and g

Re: [GENERAL] REGEXP_REPLACE woes

2008-06-11 Thread Leif B. Kristensen
For the record: I've got two different flavors of those "shortlinks". The first one, [p=123|John Smith] is the one that I started this thread with. The second one is just a person number like [p=123] and should be expanded to a similar link, with the default person name (fetched by get_person_n

Re: [GENERAL] REGEXP_REPLACE woes

2008-06-10 Thread Leif B. Kristensen
On Tuesday 10. June 2008, Michael Fuhr wrote: >Something between my message and your shell appears to have converted >a few spaces to no-break spaces. A hex dump of your query shows the >following: > > 73 65 6c 65 63 74 20 72 65 67 65 78 70 5f 72 65 |select > regexp_re| 0010 70 6c

Re: [GENERAL] REGEXP_REPLACE woes

2008-06-10 Thread Tom Lane
CaT <[EMAIL PROTECTED]> writes: > 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). You be wrong ... PG uses Tcl's regex engine, not pcre, and this behavior is as documented. No, I don't know why Henry Spencer chose to do it

Re: [GENERAL] REGEXP_REPLACE woes

2008-06-10 Thread CaT
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 = '

Re: [GENERAL] REGEXP_REPLACE woes

2008-06-10 Thread Leif B. Kristensen
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

Re: [GENERAL] REGEXP_REPLACE woes

2008-06-10 Thread Michael Fuhr
On Tue, Jun 10, 2008 at 07:41:53AM -0600, Michael Fuhr wrote: > On Tue, Jun 10, 2008 at 02:59:53PM +0200, Leif B. Kristensen wrote: > > So far, so good. But look here: > > > > pgslekt=> select link_expand('[p=123|John Smith] and [p=456|Jane Doe]'); > > link_expand > >

Re: [GENERAL] REGEXP_REPLACE woes

2008-06-10 Thread Leif B. Kristensen
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: pgslekt=> CREATE OR REPLACE FUNCTION link_expand(TEXT) RETURNS TEXT AS $$ SELECT REGEXP_REPLACE($1, E'\\[p=(\\d+?)\\|(.+?)\\]', E

Re: [GENERAL] REGEXP_REPLACE woes

2008-06-10 Thread Michael Fuhr
On Tue, Jun 10, 2008 at 02:59:53PM +0200, Leif B. Kristensen wrote: > So far, so good. But look here: > > pgslekt=> select link_expand('[p=123|John Smith] and [p=456|Jane Doe]'); > link_expand > --- >

Re: [GENERAL] REGEXP_REPLACE woes

2008-06-10 Thread Michael Fuhr
On Tue, Jun 10, 2008 at 02:25:44PM +0200, Leif B. Kristensen wrote: > Thank you Michael, I figured it was something fishy with the escaping. > When I try your example, I get > > pgslekt=> select regexp_replace( > pgslekt(>    '[p=1242|John Smith]', > pgslekt(>   e'\\[p=(\\d+)\\|(.+?)\\]', > pgsle

Re: [GENERAL] REGEXP_REPLACE woes

2008-06-10 Thread Leif B. Kristensen
I put the code into a function, link_expand(): CREATE OR REPLACE FUNCTION link_expand(TEXT) RETURNS TEXT AS $$ SELECT REGEXP_REPLACE($1, E'\\[p=(\\d+)\\|(.+?)\\]', E'\\2', 'g'); $$ LANGUAGE sql STABLE; pgslekt=> select link_expand('[p=123|John Smith]');

Re: [GENERAL] REGEXP_REPLACE woes

2008-06-10 Thread Leif B. Kristensen
On Tuesday 10. June 2008, Michael Fuhr wrote: >Parts of the regular expression need more escaping.  Try this: > >select regexp_replace( >   '[p=1242|John Smith]', >  e'\\[p=(\\d+)\\|(.+?)\\]', >  e'\\2' >); > >                  regexp_replace >--- > J

Re: [GENERAL] REGEXP_REPLACE woes

2008-06-10 Thread Michael Fuhr
On Tue, Jun 10, 2008 at 01:28:06PM +0200, Leif B. Kristensen wrote: > I want to transform the text '[p=1242|John Smith]' to > John Smith, but what I get is: > > pgslekt=> select REGEXP_REPLACE('[p=1242|John Smith]', > pgslekt(> E'[p=(\d+)|(.+?)]', > pgslekt(> E'\\2'); > regexp

[GENERAL] REGEXP_REPLACE woes

2008-06-10 Thread Leif B. Kristensen
I want to transform the text '[p=1242|John Smith]' to John Smith, but what I get is: pgslekt=> select REGEXP_REPLACE('[p=1242|John Smith]', pgslekt(> E'[p=(\d+)|(.+?)]', pgslekt(> E'\\2'); regexp_replace -- [=1242|John Smith