]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-92727: Add example of named group in doc for re.Match.__getitem__ (GH-92730)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Sat, 28 May 2022 18:28:52 +0000 (11:28 -0700)
committerGitHub <noreply@github.com>
Sat, 28 May 2022 18:28:52 +0000 (11:28 -0700)
(cherry picked from commit 642d1fa81fed8ac260e1719013d77b9dfd93920f)

Co-authored-by: Baptiste Mispelon <bmispelon@gmail.com>
Doc/library/re.rst

index 2af86d22d4598d3692c74664d7d2d3368d77e3cc..2392785d6c465bee417c275bfae61a7940eb8f93 100644 (file)
@@ -1324,6 +1324,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