我使用pdo进行此查询:
SELECT * FROM users WHERE name LIKE :name AND age > :age1 AND age < :age2
如何使用正则表达式从此查询中提取参数,以获得类似于:
的数组$arr[0] => name,
$arr[1] => age1,
$arr[2] => age2
答案 0 :(得分:0)
尝试使用此尺寸..
(:[^\s]*)\s?
以下是使用regexr.com
对此REGEX的演示这是PHP的演示
<强> test.php的强>
$query="Select * from users where name like :name and age > :age1 and age < :age2";
preg_match_all('/(:[^\s]*)\s?/',$query,$matches);
print_r($matches);
php test.php
Array
(
[0] => Array
(
[0] => :name
[1] => :age1
[2] => :age2
)
[1] => Array
(
[0] => :name
[1] => :age1
[2] => :age2
)
)