regexp_replace weirdness amounts to a bug?
regexp_replace weirdness amounts to a bug?
От:
Erik Rijkers <er@xs4all.nl>
Дата:
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
(1 row)
-- 'Abc Def' got
-- 'Abc def' expected
What do you think?
Thanks,
Erik Rijkers
Re: regexp_replace weirdness amounts to a bug?
От:
Malthe <mborch@gmail.com>
Дата:
Hi Erik,
The regexp doesn't match your string because you're not allowing for
any repeat characters, try adding a '+'.
On Wed, 16 Aug 2023 at 09:07, 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
> (1 row)
>
> -- 'Abc Def' got
> -- 'Abc def' expected
>
> What do you think?
>
> Thanks,
>
> Erik Rijkers
>
>
>
Re: regexp_replace weirdness amounts to a bug?
От:
Alvaro Herrera <alvherre@alvh.no-ip.org>
Дата:
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)