summaryrefslogtreecommitdiffstats
path: root/Doc/library/re.rst
diff options
context:
space:
mode:
authorBaptiste Mispelon <bmispelon@gmail.com>2022-05-28 18:11:08 (GMT)
committerGitHub <noreply@github.com>2022-05-28 18:11:08 (GMT)
commit642d1fa81fed8ac260e1719013d77b9dfd93920f (patch)
tree5ecb500367c05d374ea8e5d9717e95eac82ae1ac /Doc/library/re.rst
parent7fa9b7daa5a8bb5760724ac2d94f5298c60dc905 (diff)
downloadcpython-642d1fa81fed8ac260e1719013d77b9dfd93920f.zip
cpython-642d1fa81fed8ac260e1719013d77b9dfd93920f.tar.gz
cpython-642d1fa81fed8ac260e1719013d77b9dfd93920f.tar.bz2
gh-92727: Add example of named group in doc for re.Match.__getitem__ (#92730)
Diffstat (limited to 'Doc/library/re.rst')
-rw-r--r--Doc/library/re.rst8
1 files changed, 8 insertions, 0 deletions
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<first_name>\w+) (?P<last_name>\w+)", "Isaac Newton")
+ >>> m['first_name']
+ 'Isaac'
+ >>> m['last_name']
+ 'Newton'
+
.. versionadded:: 3.6