[Python-checkins] gh-92727: Add example of named group in doc for re.Match.__getitem__ (#92730)

rhettinger webhook-mailer at python.org
Sat May 28 14:11:16 EDT 2022


https://github.com/python/cpython/commit/642d1fa81fed8ac260e1719013d77b9dfd93920f
commit: 642d1fa81fed8ac260e1719013d77b9dfd93920f
branch: main
author: Baptiste Mispelon <bmispelon at gmail.com>
committer: rhettinger <rhettinger at users.noreply.github.com>
date: 2022-05-28T13:11:08-05:00
summary:

gh-92727: Add example of named group in doc for re.Match.__getitem__ (#92730)

files:
M Doc/library/re.rst

diff --git a/Doc/library/re.rst b/Doc/library/re.rst
index d099f383d1206..1b9a7b63ef5e1 100644
--- a/Doc/library/re.rst
+++ b/Doc/library/re.rst
@@ -1327,6 +1327,14 @@ Match objects support the following methods and attributes:
       >>> m[2]       # The second parenthesized subgroup.
       'Newton'
 
+   Named groups are supported as well::
+
+      >>> m = re.match(r"(?P<first_name>\w+) (?P<last_name>\w+)", "Isaac Newton")
+      >>> m['first_name']
+      'Isaac'
+      >>> m['last_name']
+      'Newton'
+
    .. versionadded:: 3.6
 
 



More information about the Python-checkins mailing list