Re: regexp_replace double quote - Mailing list pgsql-general

From David G. Johnston
Subject Re: regexp_replace double quote
Date
Msg-id CAKFQuwbqAJi2-Ge0-UCcde4oTe3Z=WXDu0kKj-VxpXRdWah7Gw@mail.gmail.com
Whole thread Raw
In response to regexp_replace double quote  (Михаил <m.nasedkin@gmail.com>)
List pgsql-general
On Mon, Aug 15, 2016 at 9:27 AM, Михаил <m.nasedkin@gmail.com> wrote:
Hi!

I need to escape double quotes only:
test=# select regexp_replace('"""{Performer,"Boomwacker ""a""
Recording""}"""', '([^"])"{2}([^"])', '\1\"\2', 'g');
                 regexp_replace
-------------------------------------------------
 """{Performer,"Boomwacker \"a"" Recording\"}"""

What is the goal you are trying to accomplish​.  Its possible to do what you ask but only if no other solution is feasible.


This is unexpected result.

But when added one symbol to ""a"" the result is right:
test=# select regexp_replace('"""{Performer,"Boomwacker ""a1""
Recording""}"""', '
​​
([^"])"{2}([^"])', '\1\"\2', 'g');
                  regexp_replace
--------------------------------------------------
 """{Performer,"Boomwacker \"a1\" Recording\"}"""


<​
([^"])"{2}([^"])> on < ""a""> consumes < ""a>​ leaving <""> which doesn't match your pattern since there is nothing before the double-quote to satisfy the [^"]

See depesz's simultaneous post for the solution using look-ahead.

David J.

pgsql-general by date:

Previous
From: hubert depesz lubaczewski
Date:
Subject: Re: regexp_replace double quote
Next
From: Ioana Danes
Date:
Subject: ERROR: MultiXactId XXXXX has not been created yet -- apparent wraparound