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

This commit is contained in:
Baptiste Mispelon 2022-05-28 20:11:08 +02:00 committed by GitHub
parent 7fa9b7daa5
commit 642d1fa81f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View 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