Capturing repeating group matches in regular expressions

James Collier james.collier at xtra.co.nz
Wed Aug 11 19:58:34 EDT 2004


Michael Hudson [ mwh at python.net ] writes:

> James Collier <james.collier at xtra.co.nz> writes:
> 
>> Is it possible to capture the results of repeating group matches in
>> the python regular expression module?
> 
> Not easily; there's a small dicussion on python-dev at the moment
> about this.  Erik Heneryd hacked up something that might be useful:
> 
> http://mail.python.org/pipermail/python-dev/attachments/20040810/a5e602ab/structmatch.py
> 
> And there's always the "use a real parser" option :-)
> 
> Cheers,
> mwh

Many thanks for the answer Michael - I take your point on the "real parser" 
option, but I don't feel that the nut I'm cracking has that thick a shell.  

It is some coincidence that this should be under current discussion on 
python-dev.  For what it's worth, I'd support Mike Coleman's PEP.

To give some more background, I'm tweaking someone else's code and therefore
I want to keep the change as concise as is reasonable. structmatch() is exactly 
what I'm looking for - but for now I'll just split the task into two parts.

  Thanks again -- James.



More information about the Python-list mailing list