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

Skip to content

Commit 642d1fa

Browse files
authored
pythongh-92727: Add example of named group in doc for re.Match.__getitem__ (python#92730)
1 parent 7fa9b7d commit 642d1fa

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
@@ -1327,6 +1327,14 @@ Match objects support the following methods and attributes:
13271327
>>> m[2] # The second parenthesized subgroup.
13281328
'Newton'
13291329

1330+
Named groups are supported as well::
1331+
1332+
>>> m = re.match(r"(?P<first_name>\w+) (?P<last_name>\w+)", "Isaac Newton")
1333+
>>> m['first_name']
1334+
'Isaac'
1335+
>>> m['last_name']
1336+
'Newton'
1337+
13301338
.. versionadded:: 3.6
13311339

13321340

0 commit comments

Comments
 (0)
0