©
本文档使用 PHP中文网手册 发布
(PECL mongo >= 0.8.1)
MongoRegex::__construct — 创建一个新的正则表达式
$regex
)创建一个新的正则表达式。
regex
以 /expr/flags 形式的正则表达式字符串。
返回一个新的正则表达式。
Example #1 MongoRegex::__construct() 例子
这个例子使用了正则表达式来查询包含匹配正则表达式的所有文档,用户名字段以 (^) 开始,一个 l 和一个元音字母 ([aeiouy]),大小写不敏感 (/i)。
<?php
$luke_search = new MongoRegex ( "/^l[aeiouy]/i" );
$cursor = $collection -> find (array( "username" => $luke_search ));
?>
[#1] calimero at creatixnet dot com [2012-05-16 09:44:03]
AFAICT, as of PHP 5.3.6, this function doesn't work correctly with any delimiter character other than plain slash (/), which is annoying if your pattern looks like a URL or file path for example (which itself may contain slashes you'll have to escape).
One can make use of the print_r($your_mongoregex_object) statement to ensure the pattern is recognized properly.