mirror of
https://github.com/python/cpython
synced 2024-09-16 02:49:57 +00:00
gh-92727: Add example of named group in doc for re.Match.__getitem__ (#92730)
This commit is contained in:
parent
7fa9b7daa5
commit
642d1fa81f
|
@ -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
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue