Skip to content
This repository was archived by the owner on May 1, 2025. It is now read-only.

Commit 074fc97

Browse files
committed
add regex info
1 parent 06b6217 commit 074fc97

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

source/reference/collection-level-filtering.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ Filters have the following syntax:
8585
}
8686
]
8787

88+
To learn more about syntax for ``regex-pattern`` and options for regular
89+
expression filtering, see :ref:`c2c-filter-regex`.
90+
8891
Filters must include either the ``database`` field or the ``databaseRegex`` field.
8992

9093
If you need the filter to match specific collections, you can use either

source/reference/collection-level-filtering/filter-regex.txt

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,63 @@ you can use regular expressions:
3636
}
3737
}
3838

39+
The regular express pattern you pass into a filter must follow the :query:`regular
40+
expression <$regex>` syntax supported by the MongoDB server.
41+
42+
The following ``options`` are available for use with regular
43+
expressions:
44+
45+
.. list-table::
46+
:header-rows: 1
47+
:widths: 20 80
48+
49+
* - Option
50+
- Description
51+
52+
* - ``i``
53+
- Case insensitivity to match upper and lower cases. For an
54+
example, see :ref:`regex-case-insensitive`.
55+
56+
* - ``m``
57+
58+
- For patterns that include anchors (i.e. ``^`` for the start,
59+
``$`` for the end), match at the beginning or end of each
60+
line for strings with multiline values. Without this option,
61+
these anchors match at beginning or end of the string. For an
62+
example, see :ref:`regex-multiline-match`.
63+
64+
If the pattern contains no anchors or if the string value has
65+
no newline characters (e.g. ``\n``), the ``m`` option has no
66+
effect.
67+
68+
* - ``x``
69+
70+
- "Extended" capability to ignore all white space characters in
71+
the ``$regex`` pattern unless escaped or included in a
72+
character class.
73+
74+
Additionally, it ignores characters in-between and including
75+
an un-escaped hash/pound (``#``) character and the next new
76+
line, so that you may include comments in complicated
77+
patterns. This only applies to data characters; white space
78+
characters may never appear within special character
79+
sequences in a pattern.
80+
81+
The ``x`` option does not affect the handling of the VT
82+
character (i.e. code 11).
83+
84+
* - ``s``
85+
86+
- Allows the dot character (i.e. ``.``) to match all
87+
characters *including* newline characters. For an example,
88+
see :ref:`regex-dot-new-line`.
89+
90+
* - ``u``
91+
92+
- Supports Unicode. This flag is accepted, but is redundant. UTF is set by
93+
default in the ``$regex`` operator, making the ``u`` option
94+
unnecessary.
95+
3996
Regular expressions in filter documents use the following fields:
4097

4198
.. list-table::

0 commit comments

Comments
 (0)