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.
MongoRegex::__construct
(PECL mongo >= 0.8.1)
MongoRegex::__construct — 新しい正規表現を作成する
説明
public MongoRegex::__construct
( string
$regex
)新しい正規表現を作成します。
パラメータ
-
regex -
正規表現 (/expr/flags 形式の文字列)。
返り値
新しい正規表現を返します。
例
例1 MongoRegex::__construct() の例
この例は、正規表現を使用してすべてのドキュメントに問い合わせ、username フィールドがその正規表現にマッチするドキュメントを取得します。
<?php
$joe_search = new MongoRegex("/j[o0]e/i");
$cursor = $collection->find(array("username" => $joe_search));
?>
calimero at creatixnet dot com
16-May-2012 09:44
