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)
|
>>> 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::
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Added re.Match.groupdict example to regex HOWTO.
|
Loading…
Reference in New Issue