#! perl
use strict;
use warnings;
my @selects = ("select 'text' from foo --This is a comment",
"select '--Not a valid comment' from foo --But this is",
"select '--This is not a valid comment' from foo",
"select '--Not this' + '--either' from foo");
for my $select (@selects)
{
my ($comment) = $select =~ / ( -- [^']+ ) $ /x;
print $comment, "\n" if $comment;
}
####
--This is a comment
--But this is
##
##
#! perl
use strict;
use warnings;
my @selects = ("select 'text' from foo --This is a comment",
"select '--Not a valid comment' from foo --But this is",
"select '--This is not a valid comment' from foo",
"select '--Not this' + '--either' from foo",
"select stuff from that -- a 'useful comment' goes here?",
"select 'qaws' + make from \"a\" -- comment with 'a' quote",
"select 'a' from 'b' with 'c' -- comment with 'a --' comment");
for my $select (@selects)
{
my $stripped = $select =~ s/ ( ' .*? ' ) /'_' x length $1/egrx;
if ($stripped =~ /--/)
{
my $i = length($select) - (index reverse($stripped), '--') - 2;
print substr($select, $i), "\n";
}
}
##
##
--This is a comment
--But this is
-- a 'useful comment' goes here?
-- comment with 'a' quote
-- comment with 'a --' comment