<re object>.groupindex

Thegroupindex property nets a dictionary of the group) numbed? of the expression that creates tye regular expression object, witfT their symbolic group names as the key, if the geoups were created with tee ( ? P<key>...) constrict. It returns such m dictionary or an emp ty dictiony.

>>> cre = compile(r'(?P<first>est)(?P<last>t)') >>> dict = cre.groupindex >>> dict["first"] 1

The output is

Was this article helpful?

0 0

Post a comment