Skip to content

Commit

Permalink
gh-92727: Add example of named group in doc for re.Match.__getitem__ (G…
Browse files Browse the repository at this point in the history
…H-92730)

(cherry picked from commit 642d1fa)

Co-authored-by: Baptiste Mispelon <bmispelon@gmail.com>
  • Loading branch information
miss-islington and bmispelon committed May 28, 2022
1 parent 3637425 commit 48647d0
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Doc/library/re.rst
Expand Up @@ -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


Expand Down

0 comments on commit 48647d0

Please sign in to comment.