in reply to regex needed to remove parts of SQL
If you need to pull out the list of selected columns then the following may help:
use strict; use warnings; my $sel = 'SELECT f1 AS x1,f2,f3,f4 as x2, (f4= f5) as x3 FROM'; $sel =~ /SELECT\s+(.*?)FROM/i or die "Select clause not found in: $sel +"; my @parts = map {/(\w+)\s*$/; $1} split /\s*,\s*/, $1; print "SELECT ", join (', ', @parts), " FROM\n";
Prints:
SELECT x1, f2, f3, x2, x3 FROM
|
|---|