Skip site navigation (1) Skip section navigation (2)

Re: regexp_replace: LF, CR, or tab

From: Bastiaan Wakkie <bwakkie(at)gmail(dot)com>
To: Osvaldo Kussama <osvaldo(dot)kussama(at)gmail(dot)com>
Cc: seiliki(at)so-net(dot)net(dot)tw, pgsql-general(at)postgresql(dot)org
Subject: Re: regexp_replace: LF, CR, or tab
Date: 2010-02-28 11:43:04
Message-ID: 4B8A56C8.3000509@gmail.com (view raw or flat)
Thread:
Lists: pgsql-general
Just for clarity: In the documentation
(http://www.postgresql.org/docs/8.4/static/functions-matching.html#FUNCTIONS-POSIX-REGEXP)
is mentioned "Flag g causes the function to find each match in the
string, not only the first one, and return a row for each such match. "
So in your example it was only matching \r so A\n\tB was returned

Cheers,

Bastiaan



Osvaldo Kussama wrote:
> 2010/2/27  <seiliki(at)so-net(dot)net(dot)tw>:
>   
>> Hi!
>>
>> I am trying to replace characters '\r', '\n', or '\t' with space character ' '. As an example, I want string "A\t\n\rB" becomes "AB".  The following statement seems to be not working. What mistake have I made?
>>
>> TIA
>>
>> CN
>> ========
>>
>> select regexp_replace(E'A\r\n\tB',E'[\r\n\t]',' ');
>>  regexp_replace
>> ----------------
>>  A
>>         B
>> (1 row)
>>
>>     
>
>
> Try:
> select regexp_replace(E'A\r\n\tB',E'[\r\n\t]',' ','g');
>
> Osvaldo
>
>   

In response to

pgsql-general by date

Next:From: Bruce MomjianDate: 2010-02-28 15:13:56
Subject: Re: [GENERAL] trouble with to_char('L')
Previous:From: Martijn van OosterhoutDate: 2010-02-28 11:36:11
Subject: Re: Putting index entries to XLog

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group