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.

# 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
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.


In reply to Re: Can I have a hard stop on a match by Eily
in thread Can I have a hard stop on a match by BillB

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.