title: Get the SELECT block of a SQL Query using regex in PHP
body: <p>I want to get the SELECT block of an SQL query, and what I'm thinking is getting the text between the words SELECT and FROM. What is the REGEX I'm supposed to use?</p>
  
  <p>Is it possible to extract the FROM, WHERE and JOIN blocks in the same manner?</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>I cannot use the <a href="http://code.google.com/p/php-sql-parser/" rel="nofollow">http://code.google.com/p/php-sql-parser/</a> because it is built for MySQL and my MSSQL queries break it. I've searched a lot for an MSSQL parser and couldn't find a ready made solution so the only way I can think of is the parse the SQL myself using regex and work on the principle that the select block is between a SELECT and FROM keyword. </p>
  
  <p><strong>EXAMPLE</strong></p>
  
  <p>For the query</p>
  
  <pre><code>SELECT STRAIGHT_JOIN a,b,c 
  FROM some_table an_alias
  WHERE d &gt; 5;
  </code></pre>
  
  <p>I want something like this to be returned:</p>
  
  <pre><code>$result['SELECT'] =&gt; 'STRAIGHT_JOIN a,b,c';
  $result['FROM'] =&gt; 'some_table an_alias';
  $result['WHERE'] =&gt; 'd&gt;5';
  </code></pre>