What is a good method for parsing an sql string into it separate components. I\'v tried with a regex, however I can\'t get it to work just right.
Say for instance:
A regular expression can parse only a regular language. That is, a language that can be expressed with a finite state machine.
Most programming languages, including SQL, cannot be expressed as a regular language, and thus cannot be parsed with regular expressions. Even doing limited tasks like splitting SQL expressions is going to be maddeningly difficult with regular expressions.
You'll need to use a more robust parser generator that can handle more complex grammars. You tag your question with PHP, so you might want to look into Lime.
You'll also need to find a grammar file for PHP compatible with the parser generator you choose. I'm not sure where to get one for PHP and Lime, but there's a pure Perl project called DBIx::MyParsePP that is based on MySQL's grammar.