Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
#I want to remove this line. #"#This line too" puts "Hello, Ruby!" #Remove this comment alone.",,,,,....'''"#Consider + this content too. puts "############I don't want to remove this content bcoz it is in qu +otes#" #But remove this content. puts "This is for testing ##sdfsfsf" ###Remove this content. puts 'This is for testing ##testing' #I want to remove this content al +one'
I have tried the following expression, $_=~s/^#.*$//; $_ =~ s/([^"|'](#)+.*[^"|'])\s*#.*$/$1/; $_ =~ s/[^"|']#.*[^"|']$//;
Please any one give me the correct regular expression to fulfill my requirement. Actually without quotes I have handled the cases easily. But I want to handle the quotes too. Thanks in advance...Desired output: puts "Hello, Ruby!" ",,,,,....'''" puts "############I don't want to remove this content bcoz it is in qu +otes#" puts "This is for testing ##sdfsfsf" puts 'This is for testing ##testing'
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Regular expression..
by Anonymous Monk on Oct 29, 2010 at 07:55 UTC | |
|
Re: Regular expression..
by JavaFan (Canon) on Oct 29, 2010 at 09:10 UTC | |
by Anonymous Monk on Oct 29, 2010 at 09:23 UTC | |
by JavaFan (Canon) on Oct 29, 2010 at 10:36 UTC | |
by Anonymous Monk on Oct 29, 2010 at 11:33 UTC | |
by Anonymous Monk on Oct 29, 2010 at 11:41 UTC | |
|
Re: Regular expression..
by raybies (Chaplain) on Oct 29, 2010 at 16:58 UTC | |
by choroba (Cardinal) on Oct 29, 2010 at 17:10 UTC | |
by raybies (Chaplain) on Oct 29, 2010 at 17:21 UTC | |
|
Re: Regular expression..
by LanX (Saint) on Oct 30, 2010 at 00:54 UTC |