Got more questions? Find advice on: ASP | SQL | XML | Windows
Welcome to RegexAdvice Sign in | Join | Help

Parse SQL in Javascript or PHP

  •  02-22-2008, 1:47 PM

    Parse SQL in Javascript or PHP

    Hello all, new to this community. Having some difficulties getting a regex to parse a standard SQL query. It make it simple I will just answer the bullet points from the 'READ FIRST' post.

    1.  Programming language used - Javascript (or if PHP is easier is accomplish this task, that can be done too)

    2. My ultimate task is to create a regex that is able to pul apart a MSSQL query, this regex should be written assuming no sub-queries are involved. I would want the regex to split the query into different indexs in an array. Example query: "SELECT table1, table2 FROM database WHERE col1 = 'text' ORDER BY col2 ASC, col1 DESC"

    So the regex could then split that query into a javascript array, so for exmaple, sql_array[0] would be the select field, sql_array[1] would be the from fields, etc... I would want it to pull out fields for SELECT, FROM, WHERE, ORDER BY, GROUP BY, and HAVING.

    I relize this regex is most certainly nothing very simple, I am just so stupid when it comes to regex's that I have no idea how I would go about writting, or using the one I found in the regexlib, to make this work. Any and all help is much appreciated and I hope I provided enough info for this.

    Thanks... 


    ... we would change the world, but God will not give us the source code ...
View Complete Thread