Regular expressions allow to give matching subgroups a name, e.g.: >>> import re >>> r = re.compile(" *(?P<X>[a-zA-Z0-9]+) *") >>> m = r.search(" as9asdfA ") This allows to extract the parenthesised match by name >>> m.group('X') 'as9asdfA' instead of by index >>> m.group(1) 'as9asdfA' 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. Do I really have to do things like if m.group(1)==m.group('X'): # found it Harald Kirsch -- ----------------+------------------------------------------------------ Harald Kirsch | kirschh at lionbioscience.com | "How old is the epsilon?" LION bioscience | +49 6221 4038 172 | -- Paul Erdös *** Please do not send me copies of your posts. ***
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