(In English: parse out the "where" expression. Split it into terms on the "and" keyword. For each term, see if it matches the pattern of an identifier followed by "=&" and keep the identifier if it does match.)$sql = 'select * from EMP where EMPNO=&eno and DEPTNO=&dno and JOB=&jo +b'; my @fields; if (my($where) = $sql =~ /\swhere\s+(.*)/i) { @fields = map /(\S*)=&/, split /\sand\s/i, $where; }
Hmm, are you sure you want the "=" to be part of the match?
p.s. This is in my opinion a somewhat fishy approach, as it depends strongly on the query being formatted in a specific way. This might suffice for your needs, if the SQL is indeed as restricted as it appears here. In other cases, I'd look at better SQL parsers, like SQL::Parser, or Ovid's article on tokenizing SQL on perl.com
In reply to Re: Regular Expression Question !!!
by bart
in thread Regular Expression Question !!!
by slg_saravanan
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |