You can use Abstract Syntax Tree of the sql expression and then extract whatever expression you are interested in.
https://github.com/tobymao/sqlglot/blob/main/posts/ast_primer.md
https://medium.com/@pabbelt/why-you-should-use-sqlglot-to-manage-your-sql-codebase-82d841c0d450