regex, repeating group

Steven Scott progoth at progoth.com
Fri May 30 18:08:53 EDT 2003


Steven Scott wrote:
> 
> regex = r'-><-\n.+?\n(?:.+?:(.*?)\n?){4}$'
> 

I suppose that since it groups from left to right, that's always group 1, so 
it keeps on getting assigned the new match, thus leaving me with only the 
last line...

if anybody cares, I kept most of the elegance and power of this solution 
while keeping it maintainable by doing this:

regex = r'-><-\n.+?\n' + 4 * r'(?:.+?:(.*)\n?)' + '$'

-- 
Steven Scott [progoth at progoth.com]
Don't give up fighting, 'til nothing else stands in your way..Don't
give up talking, until there's nothing left to say....But no matter
what you do, don't ever compromise what you believe.   --The Ataris





More information about the Python-list mailing list