(PECL mongo >= 0.8.1)
MongoRegex::__construct — 创建一个新的正则表达式
$regex
)创建一个新的正则表达式。
regex
以 /expr/flags 形式的正则表达式字符串。
返回一个新的正则表达式。
Example #1 MongoRegex::__construct() 例子
这个例子使用了正则表达式来查询包含匹配正则表达式的用户名的所有文档。
<?php
$joe_search = new MongoRegex("/j[o0]e/i");
$cursor = $collection->find(array("username" => $joe_search));
?>
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.