Re: how can I replace all instances of a pattern

From: "ktm(at)rice(dot)edu" <ktm(at)rice(dot)edu>
To: James Sharrett <jsharrett(at)tidemark(dot)net>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: how can I replace all instances of a pattern
Date: 2013-03-26 13:18:52
Message-ID: 20130326131852.GF32580@aart.rice.edu
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Steve Crawford 2013-03-26 13:22:26 Re: how can I replace all instances of a pattern
Previous Message James Sharrett 2013-03-26 13:13:39 Re: how can I replace all instances of a pattern