use strict; my ($blob) = "<record><tag1>aValue</tag1><tag2>aa:bb:cc:last</tag2></record>";
my ($result, $last) = $blob =~ /<\/tag1><tag2>(.*:(.*))<\/tag2>/i; print "$result\n"; print "$last\n"; -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Steve Sarapata Sent: Friday, October 01, 2004 8:08 AM To: [EMAIL PROTECTED] Subject: Looking for a regexp solution Hell-o gurus, First, as a lurker on this listserve I've seen some amazing code come through. Keep it up. Someday too I may be able to join the ranks of the enlightened. Second, I work in a Windows shop with a hoard of VB.NETers being the lone PERLer. I have two issues I think can be resolved using a regExp but need a push in the right direction to find a solution. The problem can best be explained using an XML example. Question 1. I'm looking for the data between an opening and closing tag. I think this somehow can be written as: $result = regularExpression; In the code below I am looking for "aValue". I have only had success using index-index-substr. This is PERL, there must be a better way. Question 2. After extracting data same as above I want the last entry in a colon delimited string. In the code below I am looking for "last". Doing index-index-substr-split does the job but this just isn't elegant enough. Any suggestions or ideas to these questions so I can demonstrate the power of PERL to the masses? TIA, Steve ## begin code use strict; use warnings; my ($blob) = "<record><tag1>aValue</tag1><tag2>aa:bb:cc:last</tag2></record>"; my ($p1, $p2, $result, @data); #question 1 $p1 = index($blob, "<tag1>"); $p2 = index($blob, "</"); $result = substr($blob, ($p1+6), ($p2-($p1+6))); print $result,"\n"; #question 2 $p1 = index($blob, "<tag2>"); $p2 = index($blob, "</",$p1); $result = substr($blob, ($p1+6), ($p2-($p1+6))); @data = split(/:/,$result); $result = $data[$#data]; print $result,"\n"; ## end code _______________________________________________ ActivePerl mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs _______________________________________________ ActivePerl mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
