Regex match not back-referencing in function

From: Thom Brown <thom(at)linux(dot)com>
To: PGSQL Mailing List <pgsql-general(at)postgresql(dot)org>
Subject: Regex match not back-referencing in function
Date: 2012-02-12 18:26:22
Message-ID: CAA-aLv7AXYpoLwohA1=3qyZgbBYUaZyXNSsrDJoHtm9R_W8eXw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi,

Could someone explain the following behaviour?

SELECT regexp_replace(E'Hello & goodbye ',E'([&])','&#' ||
ascii(E'\\1') || E';\\1');

This returns:

regexp_replace
------------------------
Hello &#92;& goodbye
(1 row)

So it matched:

SELECT chr(92);
chr
-----
\
(1 row)

But notice that when I append the value it's supposed to have matched
to the end of the replacement value, it shows it should be '&'.

Just to confirm:

SELECT ascii('&');
ascii
-------
38
(1 row)

So I'd expect the output of the original statement to be:

regexp_replace
------------------------
Hello &#38;& goodbye
(1 row)

What am I missing?

--
Thom

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2012-02-12 18:49:18 Re: Regex match not back-referencing in function
Previous Message Dmitriy Igrishin 2012-02-11 19:27:15 Unambiguous identification of the cluster.