Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
5206086e
Commit
5206086e
authored
Mar 31, 2009
by
Georg Brandl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#4882: document named group behavior a bit better.
parent
7558d57a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
7 deletions
+9
-7
Doc/library/re.rst
Doc/library/re.rst
+9
-7
No files found.
Doc/library/re.rst
View file @
5206086e
...
@@ -231,16 +231,18 @@ The special characters are:
...
@@ -231,16 +231,18 @@ The special characters are:
``(?P<name>...)``
``(?P<name>...)``
Similar to regular parentheses, but the substring matched by the group is
Similar to regular parentheses, but the substring matched by the group is
accessible via the symbolic group name *name*. Group names must be valid Python
accessible within the rest of the regular expression via the symbolic group
identifiers, and each group name must be defined only once within a regular
name *name*. Group names must be valid Python identifiers, and each group
expression. A symbolic group is also a numbered group, just as if the group
name must be defined only once within a regular expression. A symbolic group
were not named. So the group named 'id' in the example below can also be
is also a numbered group, just as if the group were not named. So the group
referenced as the numbered group 1.
named ``id`` in the example below can also be referenced as the numbered group
``1``.
For example, if the pattern is ``(?P<id>[a-zA-Z_]\w*)``, the group can be
For example, if the pattern is ``(?P<id>[a-zA-Z_]\w*)``, the group can be
referenced by its name in arguments to methods of match objects, such as
referenced by its name in arguments to methods of match objects, such as
``m.group('id')`` or ``m.end('id')``, and also by name in pattern text (for
``m.group('id')`` or ``m.end('id')``, and also by name in the regular
example, ``(?P=id)``) and replacement text (such as ``\g<id>``).
expression itself (using ``(?P=id)``) and replacement text given to
``.sub()`` (using ``\g<id>``).
``(?P=name)``
``(?P=name)``
Matches whatever text was matched by the earlier group named *name*.
Matches whatever text was matched by the earlier group named *name*.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment