That was easier:
#!/usr/bin/perl
use strict;
use warnings;
#my $line = "1elem21elema2a 1 bad13elema2eone 1 bad 1elemb2bone 2
bad1elemc2c13elemc2btwo13elemb2etwo13elem2";
my $line = "<elem1><elema>a < bad</elema>e1 < bad <elemb>b1 >
bad<elemc>c</elemc>b2</elemb>e2</elem1>";
my $cnt = 0;
my @insides = $line =~ m{ <elem1>(.*?)<\/elem1> }gmsx;
for my $inside ( @insides ){
print $inside;
while( $inside =~ m{ <([^\s<\/]*)> }gmsx ){
my $element = $1;
$cnt = $cnt +1;
# unless( $element =~ m{ \A \/ }msx ){
print "\n$cnt=$1\n";
}
#}
}
4 any one to use :)
Let me know if you see any problems...
Thanks again everyone!
--- On Thu, 1/8/09, Paul M <[email protected]> wrote:
From: Paul M <[email protected]>
Subject: RegExp Searching - part deux
To: [email protected]
Date: Thursday, January 8, 2009, 8:18 AM
What happens if I have a simple string:
my $line = "1elem21elema2a 1 bad13elema2 1 bad elemb2 bad 2 z
1elemc2c13elemc2b13elemb2e13elem2";
That must follow simply rules:
Find every alpha character string between the numbers one and two. The string
may not include the number one two or three.
SO:
1 bad13elema2 = no good, contains 1 and 3
1 bad 1elemb2 = no good, contains space
13elema2 = no good, contains 3
???