Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pattern Matching Problem

Status
Not open for further replies.

gamesthreshold

Programmer
Jul 22, 2006
4
US
I'm trying to "walk" a string, and fill $1/$2 with a string and a character which follows it. Heres an example...

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?
 
Never mind thanks anyway... Figured out how to use the non greedy *?... *oops*
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top