in reply to need to parse firts part of SQL-query (regex question)
my $part_sql = "f1,f2, SUM(f3),CONCAT(f4,f5, f6), f7"; my @fields = $part_sql =~ m{ (?: ^ | , ) # start of string or comma ( # begin capture (?: # either: [^,()] # non-paren non-comma | # or: \( # left paren [^()]* # any amount of non-paren \) # right paren )* # as often as possible ) # end capture }gx; # take all matches print map { "$_\n" } @fields;
Of course, this simplistic approach does not handle nested parentheses.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: need to parse firts part of SQL-query (regex question)
by bfdi533 (Friar) on Mar 27, 2008 at 21:32 UTC |