Thread: regexp_replace - replace non-numbers

regexp_replace - replace non-numbers

From
Vincas Dargis
Date:
Hello everyone,

I have problem with regexp_replace ( PostgreSQL 8.3.1). Please try this
crappy string replacement:

select regexp_replace('abcd1235hgj!@#$^&^&*()[]-=', '[^0-9]*' ,'')

..and I get:
"1235hgj!@#$^&^&*()[]-="

So only thirst assurance where removed, while documentation states that
"Replace substring_(s)_ matching a POSIX regular expression. ". I need
to get digits-only from any string. No sign or decimal point is needed.

I believe it's problem with my regular expression, as I am not very good
at it, thought it looks quite OK in Regex Coatch.

...or maybe there are way for 'no-errorous-blocking' casting? I could
easily skip strings witch could not be CAST'ed to bigint, but as long as
I get error and aborted transaction, I'm trying this approach.

Thanks for comments!



--


Geros dienos,

Vincas Dargis

Programuotojas
UAB "ProNENSIS"
Metalistų g. 10, Šiauliai, LT - 78136
Tel: +370 41 50 23 33
Faksas: +370 41 42 16 12


Re: regexp_replace - replace non-numbers

From
"Merlin Moncure"
Date:
On Tue, Oct 28, 2008 at 10:42 AM, Vincas Dargis <vincas.d@nensis.lt> wrote:
> Hello everyone,
>
> I have problem with regexp_replace ( PostgreSQL 8.3.1). Please try this
> crappy string replacement:
>
> select regexp_replace('abcd1235hgj!@#$^&^&*()[]-=', '[^0-9]*' ,'')
>
> ..and I get:
> "1235hgj!@#$^&^&*()[]-="
>

global flag:
select regexp_replace('abcd1235hgj!@#$^&^&*()[]-=', '[^0-9]*' ,'', 'g');

merlin

Re: regexp_replace - replace non-numbers

From
Vincas Dargis
Date:
Merlin Moncure wrote:
> On Tue, Oct 28, 2008 at 10:42 AM, Vincas Dargis <vincas.d@nensis.lt> wrote:
>
>> Hello everyone,
>>
>> I have problem with regexp_replace ( PostgreSQL 8.3.1). Please try this
>> crappy string replacement:
>>
>> select regexp_replace('abcd1235hgj!@#$^&^&*()[]-=', '[^0-9]*' ,'')
>>
>> ..and I get:
>> "1235hgj!@#$^&^&*()[]-="
>>
>>
>
> global flag:
> select regexp_replace('abcd1235hgj!@#$^&^&*()[]-=', '[^0-9]*' ,'', 'g');
>
> merlin
>
>
Thank you!

--


Geros dienos,

Vincas Dargis

Programuotojas
UAB "ProNENSIS"
Metalistų g. 10, Šiauliai, LT - 78136
Tel: +370 41 50 23 33
Faksas: +370 41 42 16 12