CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Regular Expressions:
capturing parentheses in subseraches

 



PGScooter
stranger

Jun 12, 2008, 1:21 AM

Post #1 of 3 (3430 views)
capturing parentheses in subseraches Can't Post

Hi, I know I've read this a couple of times, but forgot how it is correctly done. Suppose I do a regex search, condition on it and within that if block, I do another regex search. How do I refer to the capturing parentheses in the subsearch? Because don't $1,$2,... refer to the main search, not the nested one?

if ($string=~/(\w*)end/) {

if ($diffstring=~/$1five(\w*\d{2})/) {

print "don't know"; #how do I get what's in (\w*\d{2})?

}

}

thanks
The more you teach me, the more I learn. The more I learn, the more I teach.


KevinR
Veteran


Jun 12, 2008, 8:35 AM

Post #2 of 3 (3417 views)
Re: [PGScooter] capturing parentheses in subseraches [In reply to] Can't Post






Code
   

if ($string=~/(\w*)end/) {

$foo = $1;

if ($diffstring=~/${foo}five(\w*\d{2})/) {

print $1;

}

}



-------------------------------------------------


PGScooter
stranger

Jun 12, 2008, 1:30 PM

Post #3 of 3 (3402 views)
Re: [KevinR] capturing parentheses in subseraches [In reply to] Can't Post

ah, that definitely makes sense! For some reason I thought I had seen a special way to refer to a nested one, but your way seems perfect.



Thanks!
The more you teach me, the more I learn. The more I learn, the more I teach.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives