Re: how can I replace all instances of a pattern - Mailing list pgsql-sql

From ktm@rice.edu
Subject Re: how can I replace all instances of a pattern
Date
Msg-id 20130326131852.GF32580@aart.rice.edu
Whole thread Raw
In response to Re: how can I replace all instances of a pattern  (James Sharrett <jsharrett@tidemark.net>)
Responses Re: how can I replace all instances of a pattern
List pgsql-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



pgsql-sql by date:

Previous
From: James Sharrett
Date:
Subject: Re: how can I replace all instances of a pattern
Next
From: Steve Crawford
Date:
Subject: Re: how can I replace all instances of a pattern