OpenQuizz
Une application de gestion des contenus pédagogiques
Regex Class Reference
Inheritance diagram for Regex:
Collaboration diagram for Regex:

Public Member Functions

def from_native (cls, regex)
 
def __init__ (self, pattern, flags=0)
 
def __eq__ (self, other)
 
def __ne__ (self, other)
 
def __repr__ (self)
 
def try_compile (self)
 

Data Fields

 pattern
 
 flags
 

Detailed Description

BSON regular expression data.

Constructor & Destructor Documentation

◆ __init__()

def __init__ (   self,
  pattern,
  flags = 0 
)
BSON regular expression data.

This class is useful to store and retrieve regular expressions that are
incompatible with Python's regular expression dialect.

:Parameters:
  - `pattern`: string
  - `flags`: (optional) an integer bitmask, or a string of flag
    characters like "im" for IGNORECASE and MULTILINE

Member Function Documentation

◆ __eq__()

def __eq__ (   self,
  other 
)

◆ __ne__()

def __ne__ (   self,
  other 
)

◆ __repr__()

def __repr__ (   self)

◆ from_native()

def from_native (   cls,
  regex 
)
Convert a Python regular expression into a ``Regex`` instance.

Note that in Python 3, a regular expression compiled from a
:class:`str` has the ``re.UNICODE`` flag set. If it is undesirable
to store this flag in a BSON regular expression, unset it first::

  >>> pattern = re.compile('.*')
  >>> regex = Regex.from_native(pattern)
  >>> regex.flags ^= re.UNICODE
  >>> db.collection.insert({'pattern': regex})

:Parameters:
  - `regex`: A regular expression object from ``re.compile()``.

.. warning::
   Python regular expressions use a different syntax and different
   set of flags than MongoDB, which uses `PCRE`_. 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.

.. _PCRE: http://www.pcre.org/

◆ try_compile()

def try_compile (   self)
Compile this :class:`Regex` as a Python regular expression.

.. warning::
   Python regular expressions use a different syntax and different
   set of flags than MongoDB, which uses `PCRE`_. 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. :meth:`try_compile()` may raise
   :exc:`re.error`.

.. _PCRE: http://www.pcre.org/

Field Documentation

◆ flags

flags

◆ pattern

pattern

The documentation for this class was generated from the following file: