[Python-checkins] bpo-32913: Added re.Match.groupdict example to regex HOWTO (GH-5821)

Brett Cannon webhook-mailer at python.org
Wed Apr 17 18:43:42 EDT 2019


https://github.com/python/cpython/commit/a6de52c74d831e45ee0ff105196da8a58b9e43cd
commit: a6de52c74d831e45ee0ff105196da8a58b9e43cd
branch: master
author: josh <josh at jrl.ninja>
committer: Brett Cannon <brettcannon at users.noreply.github.com>
date: 2019年04月17日T15:43:30-07:00
summary:
bpo-32913: Added re.Match.groupdict example to regex HOWTO (GH-5821)
files:
A Misc/NEWS.d/next/Documentation/2018-02-22-15-48-16.bpo-32913.f3utho.rst
M Doc/howto/regex.rst
diff --git a/Doc/howto/regex.rst b/Doc/howto/regex.rst
index d385d991344b..d574c3736b1c 100644
--- a/Doc/howto/regex.rst
+++ b/Doc/howto/regex.rst
@@ -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
index 000000000000..caa9590abbaf
--- /dev/null
+++ b/Misc/NEWS.d/next/Documentation/2018-02-22-15-48-16.bpo-32913.f3utho.rst
@@ -0,0 +1 @@
+Added re.Match.groupdict example to regex HOWTO.


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /