pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tim Landscheidt <tim@tim-landscheidt.de>
To: pgsql-sql@postgresql.org
Subject: Re: Passing function parameters to regexp_replace
Date: Sat, 17 Sep 2011 17:07:03 +0000
Message-ID: <m3fwjvt7wo.fsf@passepartout.tim-landscheidt.de> (raw)
References: <201109171321.43309.leif@solumslekt.org>
	<201109171331.58663.leif@solumslekt.org>

Leif Biberg Kristensen <leif@solumslekt.org> wrote:

>> UPDATE sources SET source_text = regexp_replace(source_text,
>> E'n="(.*?)$1(.*?)"', E'n="\\1$2\\2"', 'g') where source_text like
>> '%n="%$2%">%';

> Sorry, I pasted a literal replacement, and substituted the parameters by hand.
> The expression should of course be

> UPDATE sources SET source_text = regexp_replace(source_text,
> E'n="(.*?)$1(.*?)"', E'n="\\1$2\\2"', 'g') where source_text like
> '%n="%$1%">%'

Try:

> UPDATE sources SET source_text = regexp_replace(source_text,
> CONCAT(E'n="(.*?)', $1, E'(.*?)"'), CONCAT(E'n="\\1', $2, '\\2"', 'g') where source_text like
> CONCAT('%n="%', $1, '%">%')

If $1 and $2 (can) include meta characters, you have to es-
cape them properly.

  Please consider that regexp_replace() uses POSIX Regular
Expressions while LIKE uses a different syntax. If possible,
I would replace the LIKE expression with its "~" equivalent
so chances of confusion are minimized.

Tim




view thread (5+ messages)  latest in thread

Message-ID: <m3fwjvt7wo.fsf@passepartout.tim-landscheidt.de>
Permalink:  ../m3fwjvt7wo.fsf@passepartout.tim-landscheidt.de/
Also on:    postgresql.org/message-id/m3fwjvt7wo.fsf@passepartout.tim-landscheidt.de

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: tim@tim-landscheidt.de
  Subject: Re: Passing function parameters to regexp_replace
  In-Reply-To: <m3fwjvt7wo.fsf@passepartout.tim-landscheidt.de>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox