in reply to Simple little regex to build a list
Assuming valid aliases must match \w+, you can say
The /i is necessary because SQL is generally case-insensitive. Note that this may return false positives if, eg, your query has a string literal with the word "as" in it, but it's a first approximation. Global (/g) match in list context returns the list of patterns matching the group (\w+). perlretut goes into this also.my @aliases = $sql =~ /\bas\s+(\w+)/ig;
Also, I don't know if this is standard or not, but some databases allow the keyword "as" to be omitted, so you can say
SELECT foo a, bar b FROM baz
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Simple little regex to build a list
by wolis (Scribe) on Feb 14, 2005 at 05:19 UTC | |
by merlyn (Sage) on Feb 14, 2005 at 05:37 UTC |