Re: regexp_replace double quote

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: Михаил <m(dot)nasedkin(at)gmail(dot)com>
Cc: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: regexp_replace double quote
Date: 2016-08-15 13:42:07
Message-ID: CAKFQuwbqAJi2-Ge0-UCcde4oTe3Z=WXDu0kKj-VxpXRdWah7Gw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Mon, Aug 15, 2016 at 9:27 AM, Михаил <m(dot)nasedkin(at)gmail(dot)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.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Ioana Danes 2016-08-15 13:48:51 ERROR: MultiXactId XXXXX has not been created yet -- apparent wraparound
Previous Message hubert depesz lubaczewski 2016-08-15 13:36:50 Re: regexp_replace double quote