Skip to content

[3.11] gh-73137: Added sub-subsection headers for flags in re (GH-93000) #93083

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 23, 2022
Merged
Changes from all 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
72 changes: 42 additions & 30 deletions Doc/library/re.rst
Original file line number Diff line number Diff line change
Expand Up @@ -665,40 +665,14 @@ functions are simplified versions of the full featured methods for compiled
regular expressions. Most non-trivial applications always use the compiled
form.


Flags
^^^^^

.. versionchanged:: 3.6
Flag constants are now instances of :class:`RegexFlag`, which is a subclass of
:class:`enum.IntFlag`.

.. function:: compile(pattern, flags=0)

Compile a regular expression pattern into a :ref:`regular expression object
<re-objects>`, which can be used for matching using its
:func:`~Pattern.match`, :func:`~Pattern.search` and other methods, described
below.

The expression's behaviour can be modified by specifying a *flags* value.
Values can be any of the following variables, combined using bitwise OR (the
``|`` operator).

The sequence ::

prog = re.compile(pattern)
result = prog.match(string)

is equivalent to ::

result = re.match(pattern, string)

but using :func:`re.compile` and saving the resulting regular expression
object for reuse is more efficient when the expression will be used several
times in a single program.

.. note::

The compiled versions of the most recent patterns passed to
:func:`re.compile` and the module-level matching functions are cached, so
programs that use only a few regular expressions at a time needn't worry
about compiling regular expressions.

.. class:: RegexFlag

Expand Down Expand Up @@ -823,6 +797,41 @@ form.
Corresponds to the inline flag ``(?x)``.


Functions
^^^^^^^^^

.. function:: compile(pattern, flags=0)

Compile a regular expression pattern into a :ref:`regular expression object
<re-objects>`, which can be used for matching using its
:func:`~Pattern.match`, :func:`~Pattern.search` and other methods, described
below.

The expression's behaviour can be modified by specifying a *flags* value.
Values can be any of the following variables, combined using bitwise OR (the
``|`` operator).

The sequence ::

prog = re.compile(pattern)
result = prog.match(string)

is equivalent to ::

result = re.match(pattern, string)

but using :func:`re.compile` and saving the resulting regular expression
object for reuse is more efficient when the expression will be used several
times in a single program.

.. note::

The compiled versions of the most recent patterns passed to
:func:`re.compile` and the module-level matching functions are cached, so
programs that use only a few regular expressions at a time needn't worry
about compiling regular expressions.


.. function:: search(pattern, string, flags=0)

Scan through *string* looking for the first location where the regular expression
Expand Down Expand Up @@ -1058,6 +1067,9 @@ form.
Clear the regular expression cache.


Exceptions
^^^^^^^^^^

.. exception:: error(msg, pattern=None, pos=None)

Exception raised when a string passed to one of the functions here is not a
Expand Down