From: | David Johnston <polobo(at)yahoo(dot)com> |
---|---|
To: | Thom Brown <thom(at)linux(dot)com> |
Cc: | PGSQL Mailing List <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: Regex match not back-referencing in function |
Date: | 2012-02-12 18:54:35 |
Message-ID: | 7AD29D0B-41C5-4806-923E-25E0F7AE59EE@yahoo.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Feb 12, 2012, at 13:26, Thom Brown <thom(at)linux(dot)com> wrote:
> 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
>
The "ASCII" function call is evaluated independently of, and before, the regexp_replace function call and so the E'\\1' has no special meaning. It only has special meaning inside of the regexp_replace function.
Try just evaluating ascii(E'\\1') by itself and confirm you get "92".
David J.
From | Date | Subject | |
---|---|---|---|
Next Message | Thom Brown | 2012-02-12 18:59:58 | Re: Regex match not back-referencing in function |
Previous Message | Tom Lane | 2012-02-12 18:49:18 | Re: Regex match not back-referencing in function |