8000 gh-92727: Add example of named group in doc for re.Match.__getitem__ … · python/cpython@48647d0 · GitHub
[go: up one dir, main page]

Skip to content

Commit 48647d0

Browse files
gh-92727: Add example of named group in doc for re.Match.__getitem__ (GH-92730)
(cherry picked from commit 642d1fa) Co-authored-by: Baptiste Mispelon <bmispelon@gmail.com>
1 parent 3637425 commit 48647d0

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

Doc/library/re.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1324,6 +1324,14 @@ Match objects support the following methods and attributes:
13241324
>>> m[2] # The second parenthesized subgroup.
13251325
'Newton'
13261326

1327+
Named groups are supported as well::
1328+
1329+
>>> m = re.match(r"(?P<first_name>\w+) (?P<last_name>\w+)", "Isaac Newton")
1330+
>>> m['first_name']
1331+
'Isaac'
1332+
>>> m['last_name']
1333+
'Newton'
1334+
13271335
.. versionadded:: 3.6
13281336

13291337

0 commit comments

Comments
 (0)
0