Thread: regular expression

regular expression

From
gurkan@resolution.com
Date:
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"

-------------------------------------------------
This mail sent through IMP: www.resolution.com


Re: regular expression

From
Gnanavel S
Date:
Try this,
select substring('6768 - THY','[0-9]*');
 substring
-----------
 6768
(1 row)

On 10/4/05, gurkan@resolution.com <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"

-------------------------------------------------
This mail sent through IMP: www.resolution.com

---------------------------(end of broadcast)---------------------------
TIP 2: Don't 'kill -9' the postmaster



--
with regards,
S.Gnanavel

Re: regular expression

From
Michael Fuhr
Date:
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


Re: regular expression

From
Michael Fuhr
Date:
[Please copy the mailing list on replies.]

On Wed, Oct 12, 2005 at 04:28:47PM -0400, gurkan@resolution.com wrote:
> Thanks for the reply. It helped a lot. I was goint to ask similar question
> regarding regular expression, but this time I need not the numeric part. What I
> mean is;
> say that this may be in these format 
>  "TSWUU"          ---need--- "TSWUU"
>  "4 - DSC"        ---need--- "DSC"
>  "6768 - THY"     ---need--- "THY"
> basically string may or may not start with number, 
> I need substring of character if it starts with number discard it

This isn't a PostgreSQL issue, but rather one of understanding how
regular expressions work in general.  See the previously mentioned
"Pattern Matching" section of the PostgreSQL documentation for the
PostgreSQL-specific details, and use a search engine to find a
regular expression tutorial; they're frequently used in Perl and
other languages so a lot of learning material exists.  If you can
find a copy in a library or bookstore, the book _Mastering Regular
Expressions_ by Jeffrey E. F. Friedl, published by O'Reilly, is a
good resource.

-- 
Michael Fuhr


Re: regular expression

From
Yasir Malik
Date:
> This isn't a PostgreSQL issue, but rather one of understanding how
> regular expressions work in general.  See the previously mentioned
> "Pattern Matching" section of the PostgreSQL documentation for the
> PostgreSQL-specific details, and use a search engine to find a
> regular expression tutorial; they're frequently used in Perl and
> other languages so a lot of learning material exists.  If you can
> find a copy in a library or bookstore, the book _Mastering Regular
> Expressions_ by Jeffrey E. F. Friedl, published by O'Reilly, is a
> good resource.
>
If you have Perl installed, do a 'man perlretut'.  It is quite a wonderful 
tutorial.  That is what I used to learn regular expressions.

Yasir