in reply to Regex: Identifying comments
How about this? I am going to match every sql with $2 and print. Ignore $1.
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)
I am not so confident with regex and add escaped test.
Then, add2 and add3 is not working well... sigh.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Regex: Identifying comments
by pvaldes (Chaplain) on Aug 30, 2012 at 18:29 UTC | |
by remiah (Hermit) on Aug 30, 2012 at 21:58 UTC | |
by pvaldes (Chaplain) on Aug 30, 2012 at 23:42 UTC | |
by remiah (Hermit) on Aug 31, 2012 at 05:37 UTC | |
by pvaldes (Chaplain) on Aug 31, 2012 at 15:32 UTC | |
|