in reply to matching comments
For your tests file I got what you wanted.while( $file =~ /\Q$start\E(.*?)\Q$end\E/sg ) { $a = $1; $match = $&; #look for more start tags in what we matched while( $a =~ /\Q$start\E/sg ) { #balance the ending comments $file =~ /.*?\Q$end\E/sg; $match .= $&; } print $match, "\n"; }
And here are my results:blah blah /* comment 1 */ blah blah /* comment 2 */ blah blah /* outer /* mid /* center */ mid */ outer */
So enjoy this fanciful result.prompt$ regex.pl '/*' '*/' /* comment 1 */ /* comment 2 */ /* outer /* mid /* center */ mid */ outer */
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
RE: Re: matching comments
by merlyn (Sage) on Apr 25, 2000 at 22:46 UTC | |
|
Re: Re: matching comments
by Anonymous Monk on Jun 25, 2002 at 03:36 UTC |