Another option could be something like this:<div><br></div><div>You can add ids to your regexp, so you can retrive them latter using groupdict. </div><div>Once you have the ids in place, you can join in a new regexp with the "|" operator which is not greedy, it will stop after the first match. </div>
<div><br></div><div>pattern = <span class="Apple-style-span" style="font-family: monospace; font-size: 12px; line-height: 20px; ">(?P<section>re_section)|</span><span class="Apple-style-span" style="font-family: monospace; font-size: 12px; line-height: 20px; ">?P<name>re_section|...</span></div>
<div><br></div><div>Then you can have another structure with the previous id and the actions you want to perform on them.</div><div><br></div><div>actions = {'section': lambda r: r[18:-5],</div><div>                'name': lambda r: r[6:-1]),</div>
<div>               ...}</div><div><br></div><div><br></div><div>Finally you just need to iterate over the result. In this case the dictionary will have only one pair.</div><div><br></div><div>result = pattern.search(line)</div>
<div>if result:</div><div>   for key,val in result.groupdict().iteritems():</div><div>       actions[key](val)</div><div><br></div><div>....</div><div><br></div><div><div>-- <br>Mauro Cáceres</div></div>