pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Need a help in regexp
4+ messages / 3 participants
[nested] [flat]

* Need a help in regexp
@ 2010-05-06 14:48 Nicholas I <nicholas.domnic.i@gmail.com>
  2010-05-06 14:53 ` Fwd: Need a help in regexp Nicholas I <nicholas.domnic.i@gmail.com>
  2010-05-06 15:04 ` Re: Need a help in regexp A. Kretschmer <andreas.kretschmer@schollglas.com>
  2010-05-06 15:37 ` Re: Need a help in regexp Leif Biberg Kristensen <leif@solumslekt.org>
  0 siblings, 3 replies; 4+ messages in thread

From: Nicholas I @ 2010-05-06 14:48 UTC (permalink / raw)
  To: pgsql-sql

Hi,

Need a help in regexp!

I have a table in which the data's are entered like,

Example:

One (1)
Two (2)
Three (3)

I want to extract the data which is only within the parentheses.

that is
1
2
3

i have written a query,
*select regexp_matches(name,'([^(]+)([)]+)','g') from table;*
which outputs the data as,
{"test"}
{"test2"}


Thank You
Nicholas I

^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Fwd: Need a help in regexp
  2010-05-06 14:48 Need a help in regexp Nicholas I <nicholas.domnic.i@gmail.com>
@ 2010-05-06 14:53 ` Nicholas I <nicholas.domnic.i@gmail.com>
  2 siblings, 0 replies; 4+ messages in thread

From: Nicholas I @ 2010-05-06 14:53 UTC (permalink / raw)
  To: pgsql-general@postgresql.org

---------- Forwarded message ----------
From: Nicholas I <nicholas.domnic.i@gmail.com>
Date: Thu, May 6, 2010 at 8:18 PM
Subject: Need a help in regexp
To: pgsql-sql@postgresql.org


Hi,

Need a help in regexp!

I have a table in which the data's are entered like,

Example:

One (1)
Two (2)
Three (3)

I want to extract the data which is only within the parentheses.

that is
1
2
3

i have written a query,
*select regexp_matches(name,'([^(]+)([)]+)','g') from table;*
which outputs the data as,
{"test"}
{"test2"}


Thank You
Nicholas I

^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: Need a help in regexp
  2010-05-06 14:48 Need a help in regexp Nicholas I <nicholas.domnic.i@gmail.com>
@ 2010-05-06 15:04 ` A. Kretschmer <andreas.kretschmer@schollglas.com>
  2 siblings, 0 replies; 4+ messages in thread

From: A. Kretschmer @ 2010-05-06 15:04 UTC (permalink / raw)
  To: pgsql-sql

In response to Nicholas I :
> Hi,
> 
> Need a help in regexp!
> 
> I have a table in which the data's are entered like,
> 
> Example:
> 
> One (1)
> Two (2)
> Three (3)
> 
> I want to extract the data which is only within the parentheses.
> 
> that is
> 1
> 2
> 3
> 
> i have written a query,
> select regexp_matches(name,'([^(]+)([)]+)','g') from table;
> which outputs the data as,
> {"test"}
> {"test2"}
> 
> 
> Thank You
> Nicholas I


test=*# select * from regex ;
     t
-----------
 one (1)
 two (2)
 three (3)
(3 Zeilen)

Zeit: 0,262 ms

test=*# select regexp_replace(t, '[^0-9]','','g') from regex;
 regexp_replace
----------------
 1
 2
 3
(3 Zeilen)


Regards, Andreas
-- 
Andreas Kretschmer
Kontakt:  Heynitz: 035242/47150,   D1: 0160/7141639 (mehr: -> Header)
GnuPG: 0x31720C99, 1006 CCB4 A326 1D42 6431  2EB0 389D 1DC2 3172 0C99



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: Need a help in regexp
  2010-05-06 14:48 Need a help in regexp Nicholas I <nicholas.domnic.i@gmail.com>
@ 2010-05-06 15:37 ` Leif Biberg Kristensen <leif@solumslekt.org>
  2 siblings, 0 replies; 4+ messages in thread

From: Leif Biberg Kristensen @ 2010-05-06 15:37 UTC (permalink / raw)
  To: pgsql-sql

On Thursday 6. May 2010 16.48.26 Nicholas I wrote:
> Hi,
> 
> Need a help in regexp!
> 
> I have a table in which the data's are entered like,
> 
> Example:
> 
> One (1)
> Two (2)
> Three (3)
> 
> I want to extract the data which is only within the parentheses.
> 
> that is
> 1
> 2
> 3
> 
> i have written a query,
> *select regexp_matches(name,'([^(]+)([)]+)','g') from table;*
> which outputs the data as,
> {"test"}
> {"test2"}

If what you've got inside the parentheses always is an integer, and it's 
always the only or first integer in the string, you can use:

SELECT (REGEXP_MATCHES(bar, E'(\\d+)'))[1] FROM foo;

You can even cast it to an integer on the fly:

SELECT (REGEXP_MATCHES(bar, E'(\\d+)'))[1]::INTEGER FROM foo;

Or as a more general case, whatever's inside (the first) set of parentheses:

SELECT (REGEXP_MATCHES(bar, E'\\((.+?)\\)'))[1] FROM foo;

regards,
-- 
Leif Biberg Kristensen
http://solumslekt.org/blog/



^ permalink  raw  reply  [nested|flat] 4+ messages in thread


end of thread, other threads:[~2010-05-06 15:37 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2010-05-06 14:48 Need a help in regexp Nicholas I <nicholas.domnic.i@gmail.com>
2010-05-06 14:53 ` Nicholas I <nicholas.domnic.i@gmail.com>
2010-05-06 15:04 ` A. Kretschmer <andreas.kretschmer@schollglas.com>
2010-05-06 15:37 ` Leif Biberg Kristensen <leif@solumslekt.org>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox