Re: Replacing characters in a string

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Luís de Sousa <luis(dot)a(dot)de(dot)sousa(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Replacing characters in a string
Date: 2010-09-14 11:14:09
Message-ID: AANLkTikY5iipYTEU1_xyFz4yNv9sRqG=5d1UZ71bQgKW@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hello

2010/9/14 Luís de Sousa <luis(dot)a(dot)de(dot)sousa(at)gmail(dot)com>:
> Hello everyone,
>
> I need to replace all occurrences of a certain character in a string.
> For that I'm using regexp_replace, but so far I only managed to
> replace the first character, here's an example:
>
>> SELECT regexp_replace('xaxx', 'x', 'e');
>  regexp_replace
> ----------------
>  eaxx
> (1 row)
>
> But the result I'd need is 'eaee'. How can I do it?

postgres=# select replace('abcdeabcde','a','x');
replace
────────────
xbcdexbcde
(1 row)

or

postgres=# SELECT regexp_replace('xaxx', 'x', 'e','g'); -- use a flag Global
regexp_replace
────────────────
eaee
(1 row)

Regards

Pavel Stehule

>
> Thanks,
>
> Luís
>
> --
> Sent via pgsql-general mailing list (pgsql-general(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-general
>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Sergey Konoplev 2010-09-14 11:23:52 Re: Replacing characters in a string
Previous Message Szymon Guz 2010-09-14 11:13:32 Re: Replacing characters in a string