------------------------------------------------------
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]

Reply via email to