@@ -41,14 +41,29 @@ Compatibility
4141Syntax
4242------
4343
44- To use :query:` $regex`, use one of the following syntaxes:
44+ To use `` $regex` `, use one of the following syntaxes:
4545
4646.. code-block:: javascript
4747
4848 { <field>: { $regex: /pattern/, $options: '<options>' } }
49- { <field>: { $regex: ' pattern', $options: ' <options>' } }
49+ { " <field>" : { " $regex": " pattern", " $options": " <options>" } }
5050 { <field>: { $regex: /pattern/<options> } }
5151
52+ .. note::
53+
54+ To use ``$regex`` with :binary:`~bin.mongodump`, you must enclose the query
55+ document in single quotes ('{ ... }') to ensure that it does not interact
56+ with your shell environment.
57+
58+ The query document must be in :ref:`Extended JSON v2
59+ <mongodb-extended-json-v2>` format (either relaxed or canonical/strict mode),
60+ which includes enclosing the field names and operators in quotes. For
61+ example:
62+
63+ .. code-block:: sh
64+
65+ mongodump -d=sample_mflix -c=movies -q='{"year": {"$regex": "20"}}'
66+
5267In MongoDB, you can also use regular expression objects (i.e.
5368``/pattern/``) to specify regular expressions:
5469
@@ -96,7 +111,7 @@ expression.
96111 * - ``x``
97112
98113 - "Extended" capability to ignore all white space characters in
99- the :query:` $regex` pattern unless escaped or included in a
114+ the `` $regex` ` pattern unless escaped or included in a
100115 character class.
101116
102117 Additionally, it ignores characters in-between and including
@@ -121,7 +136,7 @@ expression.
121136
122137.. note::
123138
124- The :query:` $regex` operator does not support the global search
139+ The `` $regex` ` operator does not support the global search
125140 modifier ``g``.
126141
127142Behavior
@@ -143,14 +158,14 @@ only use JavaScript regular expression objects (i.e. ``/pattern/``
143158
144159 { name: { $in: [ /^acme/i, /^ack/ ] } }
145160
146- You *cannot* use :query:` $regex` operator expressions inside an
147- :query:`$in`.
161+ You *cannot* use `` $regex` ` operator expressions inside an
162+ :query:`$in` operator .
148163
149164Implicit ``AND`` Conditions for the Field
150165`````````````````````````````````````````
151166
152167To include a regular expression in a comma-separated list of query
153- conditions for the field, use the :query:` $regex` operator. For example:
168+ conditions for the field, use the `` $regex` ` operator. For example:
154169
155170.. code-block:: javascript
156171
@@ -162,7 +177,7 @@ conditions for the field, use the :query:`$regex` operator. For example:
162177```````````````````````
163178
164179To use either the ``x`` option or ``s`` options, you must use the
165- :query:` $regex` operator expression *with* the :query:`$options`
180+ `` $regex` ` operator expression *with* the :query:`$options`
166181operator. For example, to specify the ``i`` and the ``s`` options, you
167182must use :query:`$options` for both:
168183
@@ -175,7 +190,7 @@ PCRE Versus JavaScript
175190``````````````````````
176191
177192To use {+pcre-abbr+}-supported features in a regular expression that
178- aren't supported in JavaScript, you must use the :query:` $regex`
193+ aren't supported in JavaScript, you must use the `` $regex` `
179194operator and specify the regular expression as a string.
180195
181196To match case-insensitive strings:
@@ -194,7 +209,7 @@ These strings match the example regular expression:
194209- ``"acme"``
195210- ``"Acme"``
196211
197- The following example uses the :query:` $regex` operator to find ``name``
212+ The following example uses the `` $regex` ` operator to find ``name``
198213field strings that match the regular expression ``"(?i)a(?-i)cme"``:
199214
200215.. code-block:: javascript
@@ -217,7 +232,7 @@ operation on both:
217232
218233 db.inventory.find( { item: { $not: /^p.*/ } } )
219234
220- - :query:` $regex` operator expressions
235+ - `` $regex` ` operator expressions
221236
222237 For example:
223238
@@ -358,7 +373,7 @@ Without the ``m`` option, the example output is:
358373 { _id: 104, sku: 'Abc789', description: 'SKU starts with A' }
359374 ]
360375
361- If the :query:` $regex` pattern does not contain an anchor, the pattern
376+ If the `` $regex` ` pattern does not contain an anchor, the pattern
362377matches against the string as a whole, as in the following example:
363378
364379.. code-block:: javascript
0 commit comments