title: Finding the index of the outer FROM clause in a SQL statement string
body: <p>I need to find the index of the actual outer 'from' in a SQL string. Here are some examples of SQL strings I would be looking for the actual FROM:</p>
  
  <pre><code>select * from table --easy  
  select *, (select top 1 col1 from anothertable) as col1 from table
  select * from table,  (select col1 from anothertable) as anothertable 
  select * from table where col1=(select top 1 col1 from anothertable) 
  </code></pre>
  
  <p>I'm sure there are many more valid SQL statements that utilize sub selects.  I think what I need is a regex or parser that knows the difference between the most outer 'from' and skips any sub 'froms'.  Of course I may not be considering other pitfalls to finding the outer 'from' so any input would be appreciated.  </p>