Dear Idealists,
I notice that when you do use the re module grouping, that it only tells you what it matched last:
Dumb Real Python Code:
>>> import re
>>> match=re.search('^(?P<letter>[a-z])*$', 'abcz')
>>> match.groupdict()
{'letter': '0'}
What happened to all the other matches. Now here is a cool idea.
Cool Improved Python Code
>>> import re
>>> match=re.search('^(?P<letter>[a-z])*$', 'abcz')
>>> match.groupdict()
{'number': '0'}
{'letter.0':'a', 'letter.1':'b', 'letter.2':'c', 'letter.3':'z'}
Now, we see all that it matched. Now the problem with this and all ideas is reverse compatibility. So an addition is also too.
>>> import re
>>> match=re.search('^(?PP<number>[a-z])* and also (?PP=letter.0)(?PP=letter.-1)$', 'abcz and also az')
>>> match.groupdict()
{'letter.0':'a', 'letter.1':'b', 'letter.2':'c', 'letter.3':'z'}
Notice how I added an extra P. I also made it so that matching it in the text is also more adaptable. Please consider this idea.
Sincerely,
Me