Thanks! I worked up this mess
#! use Smart::Comments; use strict; use warnings; my $np; $np=qr/ (?:\( # Capture the opening "(" (?: # '(?:[^']|\')*?' #' a single quote string |"(?:[^']|\")*?" #" a double quote string | [^()] # not a parentheses | (??{$np}) )* \)) # and the closing ")" /ix; my $string; my $re; $string=<<'__EOString__'; SELECT "SELECT * FROM table1 WHERE ...",'FROM WHERE' SQL FROM +table2 join(select from here to where eternity) WHERE ... __EOString__ $re=qr/ ^([^'"(]* (?:"(?:[^']|\")*?"|'(?:[^']|\')*?'|$np)? )* [^'"(]* (\bFROM\b ([^'"(]* (?:"(?:[^']|\")*?"|'(?:[^']|\')*?'|$np)? )* [^'"(]*? \bWHERE\b) /ix; # works ### $string while ($string =~ m{$re}ig) { ### @- ### @+ ### $1 ### $2 ### $3 }; exit;
yielding ...
### $string: ' SELECT "SELECT * FROM table1 WHERE ..." "FROM WH +ERE"SQL FROM table2 join(select my mother from here to where eternity +) WHERE ...' Complex regular subexpression recursion limit (32766) exceeded at RE.p +l line 45. ### @-: '0', ### '64', ### '64', ### '127' ### @+: '132', ### '64', ### '132', ### '127' ### $1: '' ### $2: 'FROM table2 join(select my mother from here to where eternity +) WHERE' ### $3: ''

In reply to Re^2: REGEX search for words not in quotes. by Anonymous Monk
in thread REGEX search for words not in quotes. by Anonymous Monk

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.