]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-92727: Add example of named group in doc for re.Match.__getitem__ (#92730)
authorBaptiste Mispelon <bmispelon@gmail.com>
Sat, 28 May 2022 18:11:08 +0000 (20:11 +0200)
committerGitHub <noreply@github.com>
Sat, 28 May 2022 18:11:08 +0000 (13:11 -0500)
Doc/library/re.rst

index d099f383d12060f7b4ca08aa4c659eafc19dcc11..1b9a7b63ef5e1bb2e898f17376c56dd994ebd6b6 100644 (file)
@@ -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