David(s),
  Thank you for your help. It works perfectly now. I am adding in both of 
y'alls names into my class file for your help.


(803 is South Carolina, which should explain the accent on the yall)


Thank you botha again.
Kristofer.

----Original Message Follows----
From: David T-G <[EMAIL PROTECTED]>
To: perl beginners cgi <[EMAIL PROTECTED]>
CC: Kristofer Hoch <[EMAIL PROTECTED]>
Subject: Re: Extract numbers from in between parentheses with regex
Date: Wed, 26 Jun 2002 14:03:52 -0500

Kristofer --

....and then Kristofer Hoch said...
%
% 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?

His method almost works for you; you simply have to change around the
parens:

   [zero] [1:55pm] ~>  \
   perl -e 'my $var = "Characters(803), Value(3)"; $var =~ /\((\d+)\)/; \
     my $output = $1 ; print "output is $output\n";'
   output is 803

When doing string matching, as you've found, () will match a pattern and
then store the result as $1 or $2 or whatever is appropriate.  David's
first example explodes a bit to

   ( \(numbers\) )

which means "start saving your place for $1 later" and "match an actual
opening paren and then some digits and an actual closing paren" and
then, finally, "you're finished saving your place for $1".  Of course,
you want the in-the-text parens outside the save-your-place expression,
so it changes from

   (\(\d+\))

to

   \((\d+)\)

and if we knew that your target digits would be the first on the line
like in the example instead of "My2Thing(803), Value(3)" which would mess
us up, we could just use

   (\d+\)

because it would simply match the digits and ignore the parens
completely.


%
% Thank you
% Kristofer


HTH & HAND

:-D
--
David T-G                      * It's easier to fight for one's principles
(play) [EMAIL PROTECTED] * than to live up to them. -- fortune cookie
(work) [EMAIL PROTECTED]
http://www.justpickone.org/davidtg/    Shpx gur Pbzzhavpngvbaf Qrprapl Npg!

<< attach3 >>




_________________________________________________________________
MSN Photos is the easiest way to share and print your photos: 
http://photos.msn.com/support/worldwide.aspx


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

Reply via email to