Skip to content

Commit 7b7fef4

Browse files
committed
Merge pull request #394
2 parents 775209c + cb09f51 commit 7b7fef4

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

docs/tutorial/crud.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,21 @@ An equivalent filter could be constructed using the :query:`$regex` operator:
375375

376376
.. seealso:: :manual:`$regex </reference/operator/query/regex>` in the MongoDB manual
377377

378+
Although MongoDB's regular expression syntax is not exactly the same as PHP's
379+
:php:`PCRE <manual/en/book.pcre.php>` syntax, :php:`preg_quote() <preg_quote>`
380+
may be used to escape special characters that should be matched as-is. The
381+
following example finds restaurants whose name starts with "(Library)":
382+
383+
.. code-block:: php
384+
385+
<?php
386+
387+
$collection = (new MongoDB\Client)->test->restaurants;
388+
389+
$cursor = $collection->find([
390+
'name' => new MongoDB\BSON\Regex('^' . preg_quote('(Library)')),
391+
]);
392+
378393
.. _php-aggregation:
379394

380395
Complex Queries with Aggregation

0 commit comments

Comments
 (0)