Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
my $string = "--This is a comment\n--This Comment continues here\nNOT a comment";
My desired output is: $string = "NOT a comment"
But when I run my code, I get $string = "--This Comment continues here"
#!/usr/bin/perl -w #use strict; my $count = 1; my $string = "--This is a comment\n--This Comment continues here\nNOT +a comment"; while( $string =~ m/^--.*\n(.*)/ ) { #Debug Output print "ORIGINAL $count: $string\n****\n"; $string = $1; #Debug Output print "\n+++\nMODIFIED $count: $string\n"; $count++; } print "DONE $count: $string\n"; exit; __OUTPUT__ +++ MODIFIED 1: --This Comment continues here DONE 2: --This Comment continues here C:\temp>perl strip.pl ORIGINAL 1: --This is a comment --This Comment continues here NOT a comment **** +++ MODIFIED 1: --This Comment continues here DONE 2: --This Comment continues here C:\temp>perl strip.pl ORIGINAL 1: --This is a comment --This Comment continues here NOT a comment **** +++ MODIFIED 1: --This Comment continues here DONE 2: --This Comment continues here
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Removing nested comments with regexes
by Thelonius (Priest) on May 18, 2003 at 21:03 UTC | |
by crenz (Priest) on May 19, 2003 at 00:31 UTC | |
by Anonymous Monk on May 18, 2003 at 21:12 UTC | |
|
Re: Removing nested comments with regexes
by graff (Chancellor) on May 19, 2003 at 01:54 UTC |