Re: replace inside regexp_replace

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: Oliver Kohll <oliver(at)agilechilli(dot)com>
Cc: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: replace inside regexp_replace
Date: 2021-06-21 15:36:48
Message-ID: CAKFQuwYXL7WUmALmrM7T=-gKJinc9NR9j04U7Wm-YwGvPxfmTw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Monday, June 21, 2021, Oliver Kohll <oliver(at)agilechilli(dot)com> wrote:

>
> select regexp_replace(
> 'here is [[my text]] to replace and [[some more]]',
> E'\\[\\[(.*?)\\]\\]',
> replace(E'\\1', ' ', '_'),
> 'g'
> );
>

Side note, you seldom want to use ā€œEā€ (escape) string literals with regexes
(or in general really) using just the simple literal syntax removes the
need for double-backslashing.

David J.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Ron 2021-06-21 21:05:22 Re: How to automatically delete idle client connections?
Previous Message hubert depesz lubaczewski 2021-06-21 14:47:52 Re: replace inside regexp_replace