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

This commit is contained in:
josh 2019-04-17 22:43:30 +00:00 committed by Brett Cannon
parent 4c3efd9cd0
commit a6de52c74d
2 changed files with 8 additions and 0 deletions

View File

@ -942,6 +942,13 @@ given numbers, so you can retrieve information about a group in two ways::
>>> m.group(1) >>> m.group(1)
'Lots' '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 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` of having to remember numbers. Here's an example RE from the :mod:`imaplib`
module:: module::

View File

@ -0,0 +1 @@
Added re.Match.groupdict example to regex HOWTO.