]> granicus.if.org Git - python/commitdiff
bpo-32913: Added re.Match.groupdict example to regex HOWTO (GH-5821)
authorjosh <josh@jrl.ninja>
Wed, 17 Apr 2019 22:43:30 +0000 (22:43 +0000)
committerBrett Cannon <brettcannon@users.noreply.github.com>
Wed, 17 Apr 2019 22:43:30 +0000 (15:43 -0700)
Doc/howto/regex.rst
Misc/NEWS.d/next/Documentation/2018-02-22-15-48-16.bpo-32913.f3utho.rst [new file with mode: 0644]

index d385d991344b2898340ef5ffa9bf7662d7365357..d574c3736b1cb78348dade8e1cd36f613d6789f7 100644 (file)
@@ -942,6 +942,13 @@ given numbers, so you can retrieve information about a group in two ways::
    >>> m.group(1)
    'Lots'
 
+Additionally, you can retrieve named groups as a dictionary with
+:meth:`~re.Match.groupdict`::
+
+   >>> m = re.match(r'(?P<first>\w+) (?P<last>\w+)', 'Jane Doe')
+   >>> m.groupdict()
+   {'first': 'Jane', 'last': 'Doe'}
+
 Named groups are handy because they let you use easily-remembered names, instead
 of having to remember numbers.  Here's an example RE from the :mod:`imaplib`
 module::
diff --git a/Misc/NEWS.d/next/Documentation/2018-02-22-15-48-16.bpo-32913.f3utho.rst b/Misc/NEWS.d/next/Documentation/2018-02-22-15-48-16.bpo-32913.f3utho.rst
new file mode 100644 (file)
index 0000000..caa9590
--- /dev/null
@@ -0,0 +1 @@
+Added re.Match.groupdict example to regex HOWTO.