pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: ktm@rice.edu <ktm@rice.edu>
To: James Sharrett <jsharrett@tidemark.net>
Cc: pgsql-sql@postgresql.org
Subject: Re: how can I replace all instances of a pattern
Date: Tue, 26 Mar 2013 08:18:52 -0500
Message-ID: <20130326131852.GF32580@aart.rice.edu> (raw)
In-Reply-To: <CD7716CB.8A7D%jsharrett@tidemark.net>
References: <CD771612.8A7C%jsharrett@tidemark.net>
	<CD7716CB.8A7D%jsharrett@tidemark.net>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-sql>

On Tue, Mar 26, 2013 at 09:13:39AM -0400, James Sharrett wrote:
> Sorry, caught a typo.  Mytext1 is correctly replaced because only one
> instance of the character (space) is in the string.
> 
> This deals with the correct characters but only does the first instance of
> the character so the output is:
> 
>     'Mytext1'
>     'Mytext 2'  (wrong)
>     'Mytext-3'  (wrong)
>     'My_text4'
>     'My!text5'
> 

Hi James,

Try adding the g flag to the regex (for global). From the documentation:

regexp_replace('foobarbaz', 'b..', 'X')
                                   fooXbaz
regexp_replace('foobarbaz', 'b..', 'X', 'g')
                                   fooXX
regexp_replace('foobarbaz', 'b(..)', E'X\\1Y', 'g')
                                   fooXarYXazY

Regards,
Ken


-- 
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql



view thread (5+ messages)  latest in thread

Message-ID: <20130326131852.GF32580@aart.rice.edu>
Permalink:  ../20130326131852.GF32580@aart.rice.edu/
Also on:    postgresql.org/message-id/20130326131852.GF32580@aart.rice.edu

 · 

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: ktm@rice.edu, jsharrett@tidemark.net
  Subject: Re: how can I replace all instances of a pattern
  In-Reply-To: <20130326131852.GF32580@aart.rice.edu>

* 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