Better subquery regex to handle formatted SQL