mirror of
https://github.com/python/cpython.git
synced 2025-11-03 03:22:27 +00:00
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:
parent
36374251aa
commit
48647d00bf
1 changed files with 8 additions and 0 deletions
|
|
@ -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
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue