Regex match not back-referencing in function - Mailing list pgsql-general

From Thom Brown
Subject Regex match not back-referencing in function
Date
Msg-id CAA-aLv7AXYpoLwohA1=3qyZgbBYUaZyXNSsrDJoHtm9R_W8eXw@mail.gmail.com
Whole thread Raw
Responses Re: Regex match not back-referencing in function  (Tom Lane <tgl@sss.pgh.pa.us>)
Re: Regex match not back-referencing in function  (David Johnston <polobo@yahoo.com>)
List 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 \& 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 && goodbye
(1 row)

What am I missing?

--
Thom

pgsql-general by date:

Previous
From: Dmitriy Igrishin
Date:
Subject: Unambiguous identification of the cluster.
Next
From: Tom Lane
Date:
Subject: Re: Regex match not back-referencing in function