@@ -45,14 +45,29 @@ Compatibility
45
45
Syntax
46
46
------
47
47
48
- To use :query:` $regex`, use one of the following syntaxes:
48
+ To use `` $regex` `, use one of the following syntaxes:
49
49
50
50
.. code-block:: javascript
51
51
52
52
{ <field>: { $regex: /pattern/, $options: '<options>' } }
53
- { <field>: { $regex: ' pattern', $options: ' <options>' } }
53
+ { " <field>" : { " $regex": " pattern", " $options": " <options>" } }
54
54
{ <field>: { $regex: /pattern/<options> } }
55
55
56
+ .. note::
57
+
58
+ To use ``$regex`` with :binary:`~bin.mongodump`, you must enclose the query
59
+ document in single quotes ('{ ... }') to ensure that it does not interact
60
+ with your shell environment.
61
+
62
+ The query document must be in :ref:`Extended JSON v2
63
+ <mongodb-extended-json-v2>` format (either relaxed or canonical/strict mode),
64
+ which includes enclosing the field names and operators in quotes. For
65
+ example:
66
+
67
+ .. code-block:: sh
68
+
69
+ mongodump -d=sample_mflix -c=movies -q='{"year": {"$regex": "20"}}'
70
+
56
71
In MongoDB, you can also use regular expression objects (i.e.
57
72
``/pattern/``) to specify regular expressions:
58
73
@@ -100,7 +115,7 @@ expression.
100
115
* - ``x``
101
116
102
117
- "Extended" capability to ignore all white space characters in
103
- the :query:` $regex` pattern unless escaped or included in a
118
+ the `` $regex` ` pattern unless escaped or included in a
104
119
character class.
105
120
106
121
Additionally, it ignores characters in-between and including
@@ -125,7 +140,7 @@ expression.
125
140
126
141
.. note::
127
142
128
- The :query:` $regex` operator does not support the global search
143
+ The `` $regex` ` operator does not support the global search
129
144
modifier ``g``.
130
145
131
146
Behavior
@@ -147,14 +162,14 @@ only use JavaScript regular expression objects (i.e. ``/pattern/``
147
162
148
163
{ name: { $in: [ /^acme/i, /^ack/ ] } }
149
164
150
- You *cannot* use :query:` $regex` operator expressions inside an
151
- :query:`$in`.
165
+ You *cannot* use `` $regex` ` operator expressions inside an
166
+ :query:`$in` operator .
152
167
153
168
Implicit ``AND`` Conditions for the Field
154
169
`````````````````````````````````````````
155
170
156
171
To include a regular expression in a comma-separated list of query
157
- conditions for the field, use the :query:` $regex` operator. For example:
172
+ conditions for the field, use the `` $regex` ` operator. For example:
158
173
159
174
.. code-block:: javascript
160
175
@@ -166,7 +181,7 @@ conditions for the field, use the :query:`$regex` operator. For example:
166
181
```````````````````````
167
182
168
183
To use either the ``x`` option or ``s`` options, you must use the
169
- :query:` $regex` operator expression *with* the :query:`$options`
184
+ `` $regex` ` operator expression *with* the :query:`$options`
170
185
operator. For example, to specify the ``i`` and the ``s`` options, you
171
186
must use :query:`$options` for both:
172
187
@@ -179,7 +194,7 @@ PCRE Versus JavaScript
179
194
``````````````````````
180
195
181
196
To use {+pcre-abbr+}-supported features in a regular expression that
182
- aren't supported in JavaScript, you must use the :query:` $regex`
197
+ aren't supported in JavaScript, you must use the `` $regex` `
183
198
operator and specify the regular expression as a string.
184
199
185
200
To match case-insensitive strings:
@@ -198,7 +213,7 @@ These strings match the example regular expression:
198
213
- ``"acme"``
199
214
- ``"Acme"``
200
215
201
- The following example uses the :query:` $regex` operator to find ``name``
216
+ The following example uses the `` $regex` ` operator to find ``name``
202
217
field strings that match the regular expression ``"(?i)a(?-i)cme"``:
203
218
204
219
.. code-block:: javascript
@@ -221,7 +236,7 @@ operation on both:
221
236
222
237
db.inventory.find( { item: { $not: /^p.*/ } } )
223
238
224
- - :query:` $regex` operator expressions
239
+ - `` $regex` ` operator expressions
225
240
226
241
For example:
227
242
@@ -362,7 +377,7 @@ Without the ``m`` option, the example output is:
362
377
{ _id: 104, sku: 'Abc789', description: 'SKU starts with A' }
363
378
]
364
379
365
- If the :query:` $regex` pattern does not contain an anchor, the pattern
380
+ If the `` $regex` ` pattern does not contain an anchor, the pattern
366
381
matches against the string as a whole, as in the following example:
367
382
368
383
.. code-block:: javascript
0 commit comments