I need a pattern that does a very specific thing but after hours I can't achieve te expected result.
Sample string:
SELECT col1 FROM tbl1 WHERE col1 = (SELECT col2 FROM tbl2 WHERE col2=col2)
Expected result:
FROM tbl1 WHERE col1 = (SELECT col2 FROM tbl2 WHERE col2=col2)
-> tbl1
-> WHERE col1 = (SELECT col2 FROM tbl2 WHERE col2=col2)
Actual pattern:
FROM\s+([^\s,]+)[\s\S]+(WHERE[\s\S]+)
Actual result:
FROM tbl1 WHERE col1 = (SELECT col2 FROM tbl2 WHERE col2=col2)
-> tbl2
-> WHERE col2=col2)
I have tried using look ahead and other things but I can't make it group from the first 'WHERE'.
Note: Between 'tbl1' and 'WHERE' should match everything posible, not just a space.
Note2: It should group all after first 'WHERE' even if there is not a where later on.