in reply to REGEX search for words not in quotes.
Some good answers to your question have already been made, but I think there is some work to do on understanding the regular expression you propose.
First, refer to the part '*?' that you used. The intent of the '?' modifier is to change the match from 'as many as possible' to 'as few as possible'. So, you get FROM table1 WHERE, the shortest match meeting the requirements.
If you remove the question mark, you would get 'FROM table1 WHERE ..." SQL FROM table2 WHERE' instead. Note that this has nothing to do with the quotes, they are just another character in the string.
So, if you want to do the shortest match and find all possible matches, you need to iterate through the string. You do that using the 'global' modifier in a scalar context:
$str='SELECT "SELECT * FROM table1 WHERE ..." SQL FROM table2 WHERE'; print "$1\n" while $str =~ /(\bFROM\b.*?\bWHERE\b)/g;
The result is two lines:
FROM table1 WHERE FROM table2 WHERE
|
---|