regex
– Tools for representing MongoDB regular expressions
Tools for representing MongoDB regular expressions.
class (pattern, flags=0)
BSON regular expression data.
classmethod
from_native
(regex)Convert a Python regular expression into a instance.
Note that in Python 3, a regular expression compiled from a str has the
re.UNICODE
flag set. If it is undesirable to store this flag in a BSON regular expression, unset it first:Parameters: Python regular expressions use a different syntax and different set of flags than MongoDB, which uses . A regular expression retrieved from the server may not compile in Python, or may match a different set of strings in Python than when used in a MongoDB query.
try_compile
()Compile this Regex as a Python regular expression.
Python regular expressions use a different syntax and different set of flags than MongoDB, which uses . A regular expression retrieved from the server may not compile in Python, or may match a different set of strings in Python than when used in a MongoDB query. try_compile() may raise .