David,
  Thank you very much for your help. Don't know Utah, I have a lot of 
friends from there. The expression you provided is almost what I am after. 
Here is my string.

my $String = "Characters(803), Value(3)";

What I am trying to get is "803", but I keep getting "(803)". Is there a way 
to get 803 without the enclosing parens?

Thank you
Kristofer

----Original Message Follows----
From: <[EMAIL PROTECTED]>
To: "Kristofer Hoch" <[EMAIL PROTECTED]>, <[EMAIL PROTECTED]>
Subject: Re: Extract numbers from in between parentheses with regex
Date: Wed, 26 Jun 2002 11:26:23 -0600

------------------------------------------------------
my $var = "(801) 555-5555"; # ya, ok so I'm in utah :)

$var =~ /(\(\d+\))/;
# real paren, escape paren, \d = digits,
# + = one or more, escape paren, real paren

my $area_code = $1; # set to what came from between the real parens
------------------------------------------------------

but if you are looking to match anything between the parens, you probably 
want something more like
this:

------------------------------------------------------
my $var = "some text (my comment) and more text";

$var =~ /(\([^\(\)]+\))/;
# real paren, escape paren, [^\(\)] =  any non ( or ),
# + = one or more, escape paren, real paren

my $matched_value = $1; # set to what came from between the real parens
------------------------------------------------------

Regards,
David


----- Original Message -----
From: "Kristofer Hoch" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Wednesday, June 26, 2002 10:21 AM
Subject: Extract numbers from in between parentheses with regex


Hi all,
   Please forgive the simple nature of this question. I have never really
used regular expression extensivly.

   Here goes. I am trying to extract a number from in between two
parenthesis. I want the first value I find (from right to left) in a string.
These numbers could be phone number area codes, or comments.

Could someone please help, so that I can shamelessly use it all over the
place?

Thank you
Kristofer.





_________________________________________________________________
Send and receive Hotmail on your mobile device: http://mobile.msn.com


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]





_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to