略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: MongoRegex::__construct

2024-05-15

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));
?>

参见

add a note add a note

User Contributed Notes 1 note

up
0
calimero at creatixnet dot com
7 years ago
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.

官方地址:https://www.php.net/manual/en/mongoregex.construct.php

北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3