Skip to content

Commit 619a67c

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 54b5e4d commit 619a67c

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
@@ -602,40 +602,14 @@ functions are simplified versions of the full featured methods for compiled
602602
regular expressions. Most non-trivial applications always use the compiled
603603
form.
604604

605+
606+
Flags
607+
^^^^^
608+
605609
.. versionchanged:: 3.6
606610
Flag constants are now instances of :class:`RegexFlag`, which is a subclass of
607611
:class:`enum.IntFlag`.
608612

609-
.. function:: compile(pattern, flags=0)
610-
611-
Compile a regular expression pattern into a :ref:`regular expression object
612-
<re-objects>`, which can be used for matching using its
613-
:func:`~Pattern.match`, :func:`~Pattern.search` and other methods, described
614-
below.
615-
616-
The expression's behaviour can be modified by specifying a *flags* value.
617-
Values can be any of the following variables, combined using bitwise OR (the
618-
``|`` operator).
619-
620-
The sequence ::
621-
622-
prog = re.compile(pattern)
623-
result = prog.match(string)
624-
625-
is equivalent to ::
626-
627-
result = re.match(pattern, string)
628-
629-
but using :func:`re.compile` and saving the resulting regular expression
630-
object for reuse is more efficient when the expression will be used several
631-
times in a single program.
632-
633-
.. note::
634-
635-
The compiled versions of the most recent patterns passed to
636-
:func:`re.compile` and the module-level matching functions are cached, so
637-
programs that use only a few regular expressions at a time needn't worry
638-
about compiling regular expressions.
639613

640614

641615
.. data:: A
@@ -744,6 +718,41 @@ form.
744718
Corresponds to the inline flag ``(?x)``.
745719

746720

721+
Functions
722+
^^^^^^^^^
723+
724+
.. function:: compile(pattern, flags=0)
725+
726+
Compile a regular expression pattern into a :ref:`regular expression object
727+
<re-objects>`, which can be used for matching using its
728+
:func:`~Pattern.match`, :func:`~Pattern.search` and other methods, described
729+
below.
730+
731+
The expression's behaviour can be modified by specifying a *flags* value.
732+
Values can be any of the following variables, combined using bitwise OR (the
733+
``|`` operator).
734+
735+
The sequence ::
736+
737+
prog = re.compile(pattern)
738+
result = prog.match(string)
739+
740+
is equivalent to ::
741+
742+
result = re.match(pattern, string)
743+
744+
but using :func:`re.compile` and saving the resulting regular expression
745+
object for reuse is more efficient when the expression will be used several
746+
times in a single program.
747+
748+
.. note::
749+
750+
The compiled versions of the most recent patterns passed to
751+
:func:`re.compile` and the module-level matching functions are cached, so
752+
programs that use only a few regular expressions at a time needn't worry
753+
about compiling regular expressions.
754+
755+
747756
.. function:: search(pattern, string, flags=0)
748757

749758
Scan through *string* looking for the first location where the regular expression
@@ -975,6 +984,9 @@ form.
975984
Clear the regular expression cache.
976985

977986

987+
Exceptions
988+
^^^^^^^^^^
989+
978990
.. exception:: error(msg, pattern=None, pos=None)
979991

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

0 commit comments

Comments
 (0)