Re: Spliting a string in plpgsql

From: "Albe Laurenz" <all(at)adv(dot)magwien(dot)gv(dot)at>
To: <jsbali(at)gmail(dot)com>, "Andreas Kretschmer *EXTERN*" <akretschmer(at)spamfence(dot)net>, <pgsql-general(at)postgresql(dot)org>
Subject: Re: Spliting a string in plpgsql
Date: 2007-05-09 06:42:59
Message-ID: AFCCBB403D7E7A4581E48F20AF3E5DB2029C1EE9@EXADV1.host.magwien.gv.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

> Jasbinder Singh Bali <jsbali(at)gmail(dot)com> schrieb:
>> I'm writing a function in plpgsql and i need to do the following:
>>
>> I have a string in the following format.
>>
>> mail.yahoo.com
>>
>> In this string, i need to figure out the number of dots in it and
split the
>> string into two on last but one dot.
>
> Number of dots:
>
> test=*# select
> length(regexp_replace('mail.yahoo.com','[^\.]','','g'));
> length
> --------
> 2
> (1 row)

I think that this is the desired split:

test=> SELECT regexp_replace('mail.yahoo.com',
E'^(.*)\\.([^.]*\\.[^.]*)$', E'\\1');
regexp_replace
----------------
mail
(1 row)

test=> SELECT regexp_replace('mail.yahoo.com',
E'^(.*)\\.([^.]*\\.[^.]*)$', E'\\2');
regexp_replace
----------------
yahoo.com
(1 row)

Yours,
Laurenz Albe

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Albe Laurenz 2007-05-09 06:47:47 Re: Building Pg 8.2.4 on AIX 5.3 doesn't produce shared libs?
Previous Message Andrej Ricnik-Bay 2007-05-09 06:38:24 Re: Views- Advantages and Disadvantages