Thread: Replace string

Replace string

From
PostgreSQL Admin
Date:
Hi,

I want to replace a title with dashes and also remove punctuation. 

e.g,  The blue fox's fur. -> The-blue-fox-fur


Thanks for any input,
J


Re: Replace string

From
"A. Kretschmer"
Date:
am  Tue, dem 10.04.2007, um 16:40:41 -0400 mailte PostgreSQL Admin folgendes:
> Hi,
> 
> I want to replace a title with dashes and also remove punctuation. 
> 
> e.g,  The blue fox's fur. -> The-blue-fox-fur

test=*# select regexp_replace(regexp_replace('The blue fox\'s fur.', ' ', '-', 'g'), '\\.', '');  regexp_replace
--------------------The-blue-fox's-fur
(1 row)


Andreas
-- 
Andreas Kretschmer
Kontakt:  Heynitz: 035242/47150,   D1: 0160/7141639 (mehr: -> Header)
GnuPG-ID:   0x3FFF606C, privat 0x7F4584DA   http://wwwkeys.de.pgp.net


Re: Replace string

From
"Rodrigo De León"
Date:
On 4/10/07, PostgreSQL Admin <postgres@productivitymedia.com> wrote:
> Hi,
>
> I want to replace a title with dashes and also remove punctuation.
>
> e.g,  The blue fox's fur. -> The-blue-fox-fur
>
>
> Thanks for any input,
> J

SELECT translate('The blue fox''s fur.', ' .''', '-')


Re: Replace string

From
PostgreSQL Admin
Date:
> test=*# select regexp_replace(regexp_replace('The blue fox\'s fur.', ' ', '-', 'g'), '\\.', '');
>    regexp_replace
> --------------------
>  The-blue-fox's-fur
> (1 row)
>
>
> Andreas
>   
Thanks for the input.


I came up with this:

REPLACE(regexp_replace('The blue fox\'s fur', '[[:punct:]]', ''), ' ', '-');