Skip to content

Commit 83aa0d1

Browse files
gh-73137: Added sub-subsection headers for flags in re (GH-93000)
Fixes GH-73137 (cherry picked from commit b7a6610) Co-authored-by: Stanley <[email protected]>
1 parent 247e059 commit 83aa0d1

File tree

1 file changed

+42
-30
lines changed

1 file changed

+42
-30
lines changed

Doc/library/re.rst

Lines changed: 42 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -665,40 +665,14 @@ functions are simplified versions of the full featured methods for compiled
665665
regular expressions. Most non-trivial applications always use the compiled
666666
form.
667667

668+
669+
Flags
670+
^^^^^
671+
668672
.. versionchanged:: 3.6
669673
Flag constants are now instances of :class:`RegexFlag`, which is a subclass of
670674
:class:`enum.IntFlag`.
671675

672-
.. function:: compile(pattern, flags=0)
673-
674-
Compile a regular expression pattern into a :ref:`regular expression object
675-
<re-objects>`, which can be used for matching using its
676-
:func:`~Pattern.match`, :func:`~Pattern.search` and other methods, described
677-
below.
678-
679-
The expression's behaviour can be modified by specifying a *flags* value.
680-
Values can be any of the following variables, combined using bitwise OR (the
681-
``|`` operator).
682-
683-
The sequence ::
684-
685-
prog = re.compile(pattern)
686-
result = prog.match(string)
687-
688-
is equivalent to ::
689-
690-
result = re.match(pattern, string)
691-
692-
but using :func:`re.compile` and saving the resulting regular expression
693-
object for reuse is more efficient when the expression will be used several
694-
times in a single program.
695-
696-
.. note::
697-
698-
The compiled versions of the most recent patterns passed to
699-
:func:`re.compile` and the module-level matching functions are cached, so
700-
programs that use only a few regular expressions at a time needn't worry
701-
about compiling regular expressions.
702676

703677
.. class:: RegexFlag
704678

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

825799

800+
Functions
801+
^^^^^^^^^
802+
803+
.. function:: compile(pattern, flags=0)
804+
805+
Compile a regular expression pattern into a :ref:`regular expression object
806+
<re-objects>`, which can be used for matching using its
807+
:func:`~Pattern.match`, :func:`~Pattern.search` and other methods, described
808+
below.
809+
810+
The expression's behaviour can be modified by specifying a *flags* value.
811+
Values can be any of the following variables, combined using bitwise OR (the
812+
``|`` operator).
813+
814+
The sequence ::
815+
816+
prog = re.compile(pattern)
817+
result = prog.match(string)
818+
819+
is equivalent to ::
820+
821+
result = re.match(pattern, string)
822+
823+
but using :func:`re.compile` and saving the resulting regular expression
824+
object for reuse is more efficient when the expression will be used several
825+
times in a single program.
826+
827+
.. note::
828+
829+
The compiled versions of the most recent patterns passed to
830+
:func:`re.compile` and the module-level matching functions are cached, so
831+
programs that use only a few regular expressions at a time needn't worry
832+
about compiling regular expressions.
833+
834+
826835
.. function:: search(pattern, string, flags=0)
827836

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

10601069

1070+
Exceptions
1071+
^^^^^^^^^^
1072+
10611073
.. exception:: error(msg, pattern=None, pos=None)
10621074

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

0 commit comments

Comments
 (0)