'Fetch the predicate in a string of SQL statements

Suppose there are many SQL statements with predicate like

SELECT * from t1 WHERE v>0;
SELECT * from t1 WHERE v>0 ORDER BY k;
UPDATE t1 SET v=1 WHERE k=1;
DELETE FROM t1 WHERE k=1;

I want to fetch the predicate like WHERE v>0 from the statements.

Considering that predicates are very diverse, it seems impossible to extract them directly with regular expressions. Are there any good methods?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source