Re: regular expression

From: Michael Fuhr <mike(at)fuhr(dot)org>
To: gurkan(at)resolution(dot)com
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: regular expression
Date: 2005-10-05 05:56:05
Message-ID: 20051005055605.GA53834@winnie.fuhr.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Mon, Oct 03, 2005 at 06:08:30PM -0400, gurkan(at)resolution(dot)com wrote:
> How do I do regular expression for the problem that I am having
> I have a string called desc, and say that this string in
>
> "TSWUU" ------ ""
> "4 - DSC" ------ "4"
> "6768 - THY" ------ "6768"
>
> basically string may or may not start with number,
> I need substring of digits parts
> ""
> "4"
> "6768"

See "Pattern Matching" in the documentation:

http://www.postgresql.org/docs/8.0/interactive/functions-matching.html

Example:

test=> SELECT id, data FROM foo;
id | data
----+------------
1 | TSWUU
2 | 4 - DSC
3 | 6768 - THY
(3 rows)

test=> SELECT id, substring(data FROM '^([[:digit:]]+)') FROM foo;
id | substring
----+-----------
1 |
2 | 4
3 | 6768
(3 rows)

--
Michael Fuhr

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Richard Huxton 2005-10-05 08:18:39 Re: MOVE in SQL vs PLPGSQL
Previous Message Gnanavel S 2005-10-05 04:56:58 Re: regular expression