title: Getting alias columns in query using REGEX
body: <p>I have searched high and low and am really struggling to find the appropriate REGEX that would help me retrieve what I want. Assume I have the following query string:</p>
  
  <pre><code>SELECT col, col2 AS c2, col3, col * col2 calc FROM...
  </code></pre>
  
  <p>I want a REGEX that will pull out everything between commas where there is a space or an "AS" that proceeds a column alias. It should also exclude the SELECT and FROM. With the example above, I would want the following matches:</p>
  
  <pre><code>col2 AS c2
  col * col2 calc
  </code></pre>
  
  <p>Essentially, this should remove col and col3 because they don't have aliases. I have tried variations of the following but have been unsuccessful (Note: $colname contains the alias):</p>
  
  <pre><code>/(SELECT|,)([^,]*{$colname}[^,]*)(FROM|,)/
  </code></pre>
  
  <p>Currently this only returns: </p>
  
  <pre><code>, col2 AS c2,
  col2 AS c2
  , col2 AS c2,
  col2 AS c2
  </code></pre>
  
  <p>I feel I am close but I need some guidance. Any suggestions are appreciated. </p>