I need an opinion about parsing SQL (Oracle) with regex.
There are pretty entertaining posts in StackOverflow that explain that regex over HTML or XML is hopeless (example).
Is that the case with SQL as well? And even if the answer is no, is the specific problem below solvable with regex? Last fallback, what else would work?
Requirement: Verify that the table names in arbitrary SQL are enclosed in square brackets (should be "[name]").
Constraint: Use ksh/bash, i.e. grep|sed|awk.
For the SQL below the script should flag bad_table as not matching (should have been [bad_table]). Should work on arbitrary SQL, here a simpler one without joins.
SELECT id
FROM [order]
WHERE id IN (SELECT oid
FROM [audit] a, bad_table d, (SELECT xid FROM [t1]) r
WHERE a.data = r.data and a.data = d.data)