| From: | "Leif B(dot) Kristensen" <leif(at)solumslekt(dot)org> |
|---|---|
| To: | pgsql-general(at)postgresql(dot)org |
| Subject: | Re: REGEXP_REPLACE woes |
| Date: | 2008-06-10 12:59:53 |
| Message-ID: | 200806101459.53074.leif@solumslekt.org |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-general |
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'<a href="./family.php?person=\\1">\\2</a>', 'g');
$$ LANGUAGE sql STABLE;
pgslekt=> select link_expand('[p=123|John Smith]');
link_expand
--------------------------------------------------
<a href="./family.php?person=123">John Smith</a>
(1 row)
So far, so good. But look here:
pgslekt=> select link_expand('[p=123|John Smith] and [p=456|Jane Doe]');
link_expand
-----------------------------------------------------------------------
<a href="./family.php?person=123">John Smith] and [p=456|Jane Doe</a>
(1 row)
Hey, I told it not to be greedy, didn't I?
--
Leif Biberg Kristensen | Registered Linux User #338009
http://solumslekt.org/ | Cruising with Gentoo/KDE
My Jazz Jukebox: http://www.last.fm/user/leifbk/
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Sim Zacks | 2008-06-10 13:10:28 | encoding confusion |
| Previous Message | Leif B. Kristensen | 2008-06-10 12:25:44 | Re: REGEXP_REPLACE woes |