From 3c1e7693dde5d18257ae691606b96eded9f6fed2 Mon Sep 17 00:00:00 2001 From: Joshua Li Date: Thu, 22 Feb 2018 15:38:40 -0500 Subject: [PATCH 1/2] bpo-32913: Added re.Match.groupdict example to regex HOWTO --- Doc/howto/regex.rst | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Doc/howto/regex.rst b/Doc/howto/regex.rst index bdf687ee455140d..8ce37b5c9d56257 100644 --- a/Doc/howto/regex.rst +++ b/Doc/howto/regex.rst @@ -939,6 +939,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\w+) (?P\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:: From fd111acbb12673fc351761b00e1228a7b4121a71 Mon Sep 17 00:00:00 2001 From: Joshua Li Date: Thu, 22 Feb 2018 15:48:49 -0500 Subject: [PATCH 2/2] adding news blurb --- .../next/Documentation/2018-02-22-15-48-16.bpo-32913.f3utho.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Documentation/2018-02-22-15-48-16.bpo-32913.f3utho.rst 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 000000000000000..caa9590abbaf3ea --- /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.