On 2023-Aug-16, Erik Rijkers wrote:

> Hello,
> 
> The following surprised me enough to think it might be a bug:
> (17devel)
> 
> select
>    regexp_replace('Abc Def'
>   , '([a-z]) ([A-Z])'
>   , '\1 ' || lower('\2')  );
> 
> regexp_replace
> ----------------
>  Abc Def

What's happening here is that the lower() is applying to the literal \2,
and the expansion of \2 to 'D' occurs afterwards, when lower() has
already executed.  Note this other example, where the literal part of
the replacement string is correctly lowercased:

select
   regexp_replace('Abc Def'
  , '([a-z]) ([A-Z])'
  , '\1 ' || lower('D\2D'));
 regexp_replace 
────────────────
 Abc dDdef
(1 fila)

I don't know how to achieve what you want.

-- 
Álvaro Herrera        Breisgau, Deutschland  —  https://www.EnterpriseDB.com/
#error "Operator lives in the wrong universe"
  ("Use of cookies in real-time system development", M. Gleixner, M. Mc Guire)


Reply via email to