On Sat, Aug 22, 2009 at 15:13, Randolph Bentson<[email protected]> wrote: > What I'm trying to show is that building a complex regular expression > from simple regular expressions isn't too hard, but getting at all the > subgroups within the outer group isn't as straightforward. I've found a > reference to "counting the opening parenthesis" which explains why there > are two groups returned, but it seems the groups dynamically generated by > '+' and '*' don't accumulate. Is that true, or is there hope for more?
Groups are never generated dynamically. the Nth group in a regex corresponds to its Nth open parenthesis. You might want to use re.split(): >>> import re >>> re.split(r'(AB+)', 'ABABBABBBABBBBABBBBBABBBBBB') ['', 'AB', '', 'ABB', '', 'ABBB', '', 'ABBBB', '', 'ABBBBB', '', 'ABBBBBB', ''] Luke
