Re: regular expression - Mailing list pgsql-sql

From Michael Fuhr
Subject Re: regular expression
Date
Msg-id 20051005055605.GA53834@winnie.fuhr.org
Whole thread Raw
In response to regular expression  (gurkan@resolution.com)
List pgsql-sql
On Mon, Oct 03, 2005 at 06:08:30PM -0400, gurkan@resolution.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


pgsql-sql by date:

Previous
From: Gnanavel S
Date:
Subject: Re: regular expression
Next
From: Richard Huxton
Date:
Subject: Re: MOVE in SQL vs PLPGSQL