From 642d1fa81fed8ac260e1719013d77b9dfd93920f Mon Sep 17 00:00:00 2001 From: Baptiste Mispelon Date: Sat, 28 May 2022 20:11:08 +0200 Subject: gh-92727: Add example of named group in doc for re.Match.__getitem__ (#92730) --- Doc/library/re.rst | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Doc/library/re.rst b/Doc/library/re.rst index d099f38..1b9a7b6 100644 --- a/Doc/library/re.rst +++ b/Doc/library/re.rst @@ -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\w+) (?P\w+)", "Isaac Newton") + >>> m['first_name'] + 'Isaac' + >>> m['last_name'] + 'Newton' + .. versionadded:: 3.6 -- cgit v0.12