OK、これはここに投稿するには難しすぎるように思えるかもしれませんので、ご容赦ください。これにほぼ1週間取り組んできました。
特定の Oracle SQL 文字列で選択したすべての列を抽出する必要があります。次のテスト ケースに合格する必要があります。
// single column test
select col1 from dual
    // ^ should match "col1"
// multiple column test
select col1,col2 from dual
    // ^ should match "col1", "col2"
// multiple space test
select   col1   ,  col2   from   dual
    // ^ should match "col1", "col2"
// "distinct" tests
select distinct col1 from dual
    // ^ should match "col1"
select distinct col1, col2 from dual
    // ^ should match "col1", "col2"
// "distinct" with whitespaces tests
select   distinct   col1   from   dual
    // ^ should match "col1"
select   distinct   col1  ,  col2  from   dual
    // ^ should match "col1", "col2"
// "as" tests
select col1 from dual
    // ^ should match "col1"
select colA as col1 from dual
    // ^ should match "col1"
select colA as col1, col2, col3 from dual
    // ^ should match "col1", "col2", "col3"
select col1, colB as col2, col3 from dual
    // ^ should match "col1", "col2", "col3"
select col1, col2, colC as col3 from dual
    // ^ should match "col1", "col2", "col3"
// "as" tests with whitespaces tests
select    colA    as    col1,    colB    as    col2,    colC    as    col3    from    dual
    // ^ should match "col1", "col2", "col3"
// "distinct" with "as" tests
select distinct colA as col1 from dual
    // ^ should match "col1"
select distinct colA as col1, colB as col2, col3 from dual
    // ^ should match "col1", "col2", "col3"
select distinct colA as col1, col2, colC as col3 from dual
    // ^ should match "col1", "col2", "col3"
// function test
select funct('1','2') as col1 from dual
    // ^ should match "col1"
select col1, funct('1','2') as col2 from dual
    // ^ should match "col1", "col2"
select col1, colB as col2, funct('1','2') as col3 from dual
    // ^ should match "col1", "col2", "col3"
Javaで次の正規表現を試しました
 ((?<=select\ )(?!distinct\ ).*?(?=,|from))
 ((?<=select\ distinct\ ).*?(?=,|from))
 ((?<=as\ ).*?(?=,|from))
 ((?<=,\ ).*?(?=,|from))(?!.*\ as\ ) // <- Right, I'm guessing here
それらを OR で結合しましたが、上記のすべてのテスト ケースを単純にパスすることはできません。(このツールを使用して正規表現を検証しています)。
SQL エバリュエーターを検索してみましたが、実際のデータベースに対して実行せずにすべての列を抽出し、参照されるすべてのテーブルと関数が存在すると想定するものは見つかりません。
Java ReGex、テストに合格できる無料の SQL エバリュエーター (実際のデータベースは必要ありません)、またはこれら 2 つよりも優れたものが受け入れられる答えです。SQL は常に Oracle 11g 形式であることが前提です。