Skip to content
This repository was archived by the owner on May 1, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions source/reference/collection-level-filtering.txt
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ Filters have the following syntax:
}
]

To learn more about syntax for ``pattern`` and ``options`` for regular
expression filtering, see :ref:`c2c-filter-regex`.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[optional / suggestion] (brevity)
Optional edit to trim this sentence by a couple of words

Suggested change
To learn more about syntax for ``pattern`` and ``options`` for regular
expression filtering, see :ref:`c2c-filter-regex`.
To learn more about the ``pattern`` and ``options`` regular expression syntax, see :ref:`c2c-filter-regex`.


Filters must include either the ``database`` field or the ``databaseRegex`` field.

If you need the filter to match specific collections, you can use either
Expand Down
55 changes: 55 additions & 0 deletions source/reference/collection-level-filtering/filter-regex.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,61 @@ you can use regular expressions:
}
}

The regular expression pattern you pass into a filter must follow the :query:`regex <$regex>` syntax supported by the MongoDB server.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we just link to the server’s own regexp docs? That seems better than duplicating the information here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The :query:regex <$regex> section does link out to the server's own regex docs, but I can also remove the options section and also link out to the server regex docs as the options are the same as the server regex docs!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To address your overarching comment about adding an example, there is an example on the filter-regex page of matching with multiple regex options, but I tried to make the lead in text clearer for it and added a better title to make that more clear.


Regular expressions in filter documents use the following ``options``:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It’d be good to clarify that options is a string of concatenated options.


.. list-table::
:header-rows: 1
:widths: 20 80

* - Option
- Description

* - ``i``
- Case insensitivity to match upper and lower cases. For an
example, see :ref:`regex-case-insensitive`.

* - ``m``

- For patterns that include anchors (i.e. ``^`` for the start,
``$`` for the end), match at the beginning or end of each
line for strings with multiline values. Without this option,
these anchors match at beginning or end of the string. For an
example, see :ref:`regex-multiline-match`.

If the pattern contains no anchors or if the string value has
no newline characters (e.g. ``\n``), the ``m`` option has no
effect.

* - ``x``

- "Extended" capability to ignore all white space characters in
the ``$regex`` pattern unless escaped or included in a
character class.

Additionally, it ignores characters in-between and including
an un-escaped hash/pound (``#``) character and the next new
line, so that you may include comments in complicated
patterns. This only applies to data characters; white space
characters may never appear within special character
sequences in a pattern.

The ``x`` option does not affect the handling of the VT
character (i.e. code 11).

* - ``s``

- Allows the dot character (i.e. ``.``) to match all
characters *including* newline characters. For an example,
see :ref:`regex-dot-new-line`.

* - ``u``

- Supports Unicode. This flag is accepted, but is redundant. UTF is set by
default in the ``$regex`` operator, making the ``u`` option
unnecessary.

Regular expressions in filter documents use the following fields:

.. list-table::
Expand Down