Loosen regex to allow nested function calls in SQL

This essentially is a recursive regex to ensure balanced parentheses.
Partially fixes regressions from #420 including #424, but not SQL subqueries.