in reply to Regular Expression Pieces

I don't know how to do exactly what you trying, but i know how to get the results you want.
my $a = "this is a test [[1]] [[ a ]] [[ abd ]] [[\%object,key]]"; my @x = $a =~ m/(\[\[.*?\]\])/g; print "@x\n";

------
We are the carpenters and bricklayers of the Information Age.

Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.

Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.

Replies are listed 'Best First'.
Re: Re: Regular Expression Pieces
by donno20 (Sexton) on May 08, 2003 at 08:25 UTC
    How to interpret .*?
    ^_^
      ? is the modifier that says do a minimal match vs. a maximal match. Run the following code:
      my $x = "aabaab"; my ($y1) = $x =~ /([ab]+)/; my ($y2) = $x =~ /([ab]+?)/; print "$x -> '$y1' '$y2'\n";

      ------
      We are the carpenters and bricklayers of the Information Age.

      Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.

      Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.