Re: how can I replace all instances of a pattern
| От | ktm@rice.edu |
|---|---|
| Тема | Re: how can I replace all instances of a pattern |
| Дата | |
| Msg-id | 20130326131852.GF32580@aart.rice.edu обсуждение исходный текст |
| Ответ на | Re: how can I replace all instances of a pattern (James Sharrett <jsharrett@tidemark.net>) |
| Ответы |
Re: how can I replace all instances of a pattern
|
| Список | 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 по дате отправления: