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!
msg05594/pgp00000.pgp
Description: PGP signature