note
remiah
<p>
How about this? I am going to match every sql with $2 and print. Ignore $1.
<code>
use strict;
use warnings;
while (<DATA>) {
chomp;
while (m/(--.*?$) #that is comment
|
((?:'[^']*'|[^'-]*)) #quated part of sql or ordinal part
/xg) { #global, extended
print $2 if $2;
}
print "\n";
}
__DATA__
select 'text' from foo --This is a comment
select '--Not a valid comment' from foo --But this is
select q from z -- as is this
select '--This is not a valid comment' from foo
select '--Not this' + '--either' from foo
select 'qaws' + make from "a" -- comment with 'a' quote
select 'a' from 'b' with 'c' -- comment with 'a --' comment
-- test comment (add1)
select 'text\'s' from foo --escaped ... (add2)
select 'text\'s' from foo --escaped' ... (add3)
</code>
</p>
<p>
I am not so confident with regex and add escaped test.<br>
Then, add2 and add3 is not working well... sigh.
</p>
990479
990479