I'm fairly useless when it comes to regular expressions, but I'm trying to write a regular expression to parse a section out of a regular, everyday SQL statement. I think this should be pretty straightforward for someone who has some comfort with regexs. Take the following statements, for instance:
SELECT * FROM stuff 1, stuff 2
SELECT * FROM stuff 1, stuff 2 ORDER BY blah
SELECT user1, u.user2 as myuser FROM usera, userb AS u, userc LEFT JOIN userd ON blah = blah2 WHERE stuff1 = stuff2 ORDER BY stuff1
What I need is a reg ex that, when fed either of those statements (or any other SELECT statement, this needs to be robust enough to work for any valid SELECT statement thrown at it) returns ONLY the text in the FROM clause. So for the above, it would return
stuff 1, stuff 2
stuff 1, stuff 2
usera, userb AS u, userc LEFT JOIN userd ON blah = blah2
The part I'm having trouble with is telling the regex that the WHERE fields and ORDER BY fields are optional. I hate regexs...
Start Free Trial