Thread

  1. regexp_replace weirdness amounts to a bug?

    Erik Rijkers <er@xs4all.nl> — 2023-08-16T09:09:02Z

    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
    
    
    
    
    
  2. Re: regexp_replace weirdness amounts to a bug?

    Malthe <mborch@gmail.com> — 2023-08-16T09:09:05Z

    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 <er@xs4all.nl> 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
    >
    >
    >
    
    
    
    
  3. Re: regexp_replace weirdness amounts to a bug?

    Alvaro Herrera <alvherre@alvh.no-ip.org> — 2023-08-16T10:07:43Z

    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)