php教程

MongoRegex::__construct

(PECL mongo >= 0.8.1)

MongoRegex::__construct创建一个新的正则表达式

说明

public MongoRegex::__construct ( string $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));
?>

参见

User Contributed Notes

calimero at creatixnet dot com 16-May-2012 09:44
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.

CopyRight © 2008-2022 verySource.Com All Rights reserved. 京ICP备17048824号-1 京公网安备:11010502034788