mirror of
https://github.com/python/cpython
synced 2024-09-05 08:17:45 +00:00
bpo-32913: Added re.Match.groupdict example to regex HOWTO (GH-5821)
This commit is contained in:
parent
4c3efd9cd0
commit
a6de52c74d
|
@ -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::
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
Added re.Match.groupdict example to regex HOWTO.
|
Loading…
Reference in a new issue