Improving my Regex?
| From: | Gerard Samuel | Date: | Fri, 11 Jun 2004 04:00:18 +0000 |
| Subject: | Improving my Regex? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-188086@lists.php.net to get a copy of this message | ||
Looking for suggestions on if this bit of code can be improved..
The goal. To extract the conditions in the WHERE of an sql statement.
I would appreciate any pointers you may have...
Thanks
----
<?php
$hello = 'Hello';
$world = 'World';
$foo_bar = 'foo bar';
$sql = "SELECT FROM TABLE WHERE id = 1, greeting = '$hello', destination =
'$world', what = '$foo_bar' ORDER BY some_id";
header('content-type: text/plain');
$regex = '/([a-z0-9_]+)\s?=\s?(\d+|\'.*?\')/';
preg_match_all($regex, $sql, $match, PREG_SET_ORDER);
var_dump($sql, $regex, $match);
?>