summaryrefslogtreecommitdiffstats
path: root/Doc
diff options
context:
space:
mode:
authorEric V. Smith <eric@trueblade.com>2016-09-11 12:55:43 (GMT)
committerEric V. Smith <eric@trueblade.com>2016-09-11 12:55:43 (GMT)
commit605bdae0780a1ff8a88b80e6e67f3f355fb2ddb4 (patch)
tree2bb1f4625ba02d82fec908d179535a2d8147f73a /Doc
parenta3c1728bb6641208a9e253af4ffeda23bc464bbe (diff)
downloadcpython-605bdae0780a1ff8a88b80e6e67f3f355fb2ddb4.zip
cpython-605bdae0780a1ff8a88b80e6e67f3f355fb2ddb4.tar.gz
cpython-605bdae0780a1ff8a88b80e6e67f3f355fb2ddb4.tar.bz2
Issue 24454: Improve the usability of the re match object named group API
Diffstat (limited to 'Doc')
-rw-r--r--Doc/library/re.rst16
1 files changed, 16 insertions, 0 deletions
diff --git a/Doc/library/re.rst b/Doc/library/re.rst
index 87cd553..8ffcd9a 100644
--- a/Doc/library/re.rst
+++ b/Doc/library/re.rst
@@ -1015,6 +1015,22 @@ Match objects support the following methods and attributes:
'c3'
+.. method:: match.__getitem__(g)
+
+ This is identical to ``m.group(g)``. This allows easier access to
+ an individual group from a match:
+
+ >>> m = re.match(r"(\w+) (\w+)", "Isaac Newton, physicist")
+ >>> m[0] # The entire match
+ 'Isaac Newton'
+ >>> m[1] # The first parenthesized subgroup.
+ 'Isaac'
+ >>> m[2] # The second parenthesized subgroup.
+ 'Newton'
+
+ .. versionadded:: 3.6
+
+
.. method:: match.groups(default=None)
Return a tuple containing all the subgroups of the match, from 1 up to however