gamesthreshold
Programmer
I'm trying to "walk" a string, and fill $1/$2 with a string and a character which follows it. Heres an example...
My problem, is that the * character is greedy and continues to the end of the string, hence printing out:
1: TESTING();; 2: ;
When I need and expect this to be printed:
1: TESTING; 2: (;
1: ; 2: );
1: ; 2: ;;
I tried using the nongreedy *?, but of course did no good as it filled $1 with just a single character.
PLZ HELP! Any ideas on how I can solve this pattern matching problem of mine?
Code:
my $istr = "TESTING();";
pos $istr = 0;
while (pos $istr < length $istr) {
if ( $istr =~ m{
\G (.*) ([ (); ])
}gcxms ) {
print("1: $1; 2: $2;\n");
}
}
My problem, is that the * character is greedy and continues to the end of the string, hence printing out:
1: TESTING();; 2: ;
When I need and expect this to be printed:
1: TESTING; 2: (;
1: ; 2: );
1: ; 2: ;;
I tried using the nongreedy *?, but of course did no good as it filled $1 with just a single character.
PLZ HELP! Any ideas on how I can solve this pattern matching problem of mine?