in reply to Can I have a hard stop on a match
Edit: actually I think holli's answer is better. It's just easier to use a tool designed specifically for SQL rather than try to parse the request and try to think of all the edge cases.
You should switch to Ruby and use the (?~ ) construct which makes solving your problem easier. While it is possible to solve your problem in a single regex, using more advanced features, there's also the simpler solution of dividing the problem in more simple steps. For example you could first extract the string between INSERT and either ( or SELECT, and then search for DOC in that substring.
By the way, [\(|values|select] means "either (, or | or v, or a, or l, or u, or e, or s, or | or s....", grouping is done with parentheses.# Untested my $ScanString =~ / ( # start of capture + INSERT .*? # the ? after * means + the shortest possible match ) # end of capture (?:\(|values|select|;) # (?: thing ) group +s without capturing /six; # s allows .* to match across several lines +. x allows spaces and comments in the regex my $substring = $1; my $found_doc = $substring =~ /\b doc \b/ix; # \b means boundary, so b +eginning or end of a word
|
|---|