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

(cherry picked from commit 642d1fa81f)

Co-authored-by: Baptiste Mispelon <bmispelon@gmail.com>
This commit is contained in:
Miss Islington (bot) 2022-05-28 11:28:52 -07:00 committed by GitHub
parent 36374251aa
commit 48647d00bf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View 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