A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://mail.python.org/pipermail/python-list/2001-April/109616.html below:

module re, how to map match group names to their int index

module re, how to map match group names to their int index module re, how to map match group names to their int indexAndrew Kuchling akuchlin at mems-exchange.org
Wed Apr 25 10:26:54 EDT 2001
Harald Kirsch <kirschh at lionbioscience.com> writes:
> I would like to have the mapping from the index to the name, i.e. if
> m.group(i) matches, I would like to know if there is a name
> corresponding to i. In the above example this would give me "X" for
> i==1. I can't find anything obvious in the re module.

You'd have to invert the .groupindex dictionary attribute of the compiled
pattern.  Following your example:

>>> r.groupindex
{'X': 1}

--amk


More information about the Python-list mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4