Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
Cpython
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
sip
Cpython
Commits
b7a6610b
Unverified
Commit
b7a6610b
authored
May 23, 2022
by
Stanley
Committed by
GitHub
May 23, 2022
Browse files
Options
Downloads
Patches
Plain Diff
gh-73137: Added sub-subsection headers for flags in re (#93000)
Fixes #73137
parent
ac718d35
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
Doc/library/re.rst
+42
-30
42 additions, 30 deletions
Doc/library/re.rst
with
42 additions
and
30 deletions
Doc/library/re.rst
+
42
−
30
View file @
b7a6610b
...
@@ -667,40 +667,14 @@ functions are simplified versions of the full featured methods for compiled
...
@@ -667,40 +667,14 @@ functions are simplified versions of the full featured methods for compiled
regular expressions. Most non-trivial applications always use the compiled
regular expressions. Most non-trivial applications always use the compiled
form.
form.
Flags
^^^^^
.. versionchanged:: 3.6
.. versionchanged:: 3.6
Flag constants are now instances of :class:`RegexFlag`, which is a subclass of
Flag constants are now instances of :class:`RegexFlag`, which is a subclass of
:class:`enum.IntFlag`.
: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
.. class:: RegexFlag
...
@@ -825,6 +799,41 @@ form.
...
@@ -825,6 +799,41 @@ form.
Corresponds to the inline flag ``(?x)``.
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)
.. function:: search(pattern, string, flags=0)
Scan through *string* looking for the first location where the regular expression
Scan through *string* looking for the first location where the regular expression
...
@@ -1061,6 +1070,9 @@ form.
...
@@ -1061,6 +1070,9 @@ form.
Clear the regular expression cache.
Clear the regular expression cache.
Exceptions
^^^^^^^^^^
.. exception:: error(msg, pattern=None, pos=None)
.. exception:: error(msg, pattern=None, pos=None)
Exception raised when a string passed to one of the functions here is not a
Exception raised when a string passed to one of the functions here is not a
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment