bson | regex functions
This subsection describes functions for working with BSON regex values.
BSON (Binary JSON) is a binary representation of JSON-like documents used primarily by MongoDB. Some systems that implement MongoDB-compatible APIs, such as Azure Cosmos DB, also support BSON documents.
A BSON Regular Expression is a binary format that stores search patterns and their matching rules. It consists of two null-terminated UTF-8 strings (cstrings):
•Pattern: The regex string itself.
•Options: A string of flags that determines matching behavior. These characters must be stored in alphabetical order.
The following options are supported:
•i (Case-insensitive): Matches both upper- and lowercase letters (e.g., A matches a).
•m (Multiline): Makes anchors ^ and $ match the start and end of each line, rather than the start and end of the entire string.
•s (Dotall): Allows the dot (.) character to match everything, including newline characters.
•u (Unicode): Enables Unicode support for shorthand character classes like \w (word characters) and \d (digits).
•x (Verbose): Ignores whitespace within the pattern and allows for comments (starting with #), which makes complex patterns easier to read.
The BSON regex functions enable you to:
•Extract either regex part (regex-options and regex-pattern).
•Create a BSON regular expression using the specified pattern and options (to-regex).
Useful links