match.groupdict() into a single dict

Ganesh Pal ganesh1pal at gmail.com
Thu Apr 20 04:01:30 EDT 2017


apologies for spamming  and Sorry my bad  the solution suggested by MRAB
works fine : )

with open("/tmp/2.repo","r") as f:
     for line in f:
         for line in f:
             result = re.search(r'MSG=attempt to record(.*)LINSNAP', line)
             if result:
                subpatterns = [r'(?P<Block>(\d+,\d+,\d+:\d+))',

 r'(?P<p_owner>([0-9a-fA-F]+:[0-9a-fA-F]+:[0-9a-fA-F]+::HEAD))',

 r'(?P<a_owner>(owner:\s+[0-9a-fA-F]+:[0-9a-fA-F]+:[0-9a-fA-F]+::HEAD))',
                               '.']
                pattern = '(%s)*' % '|'.join(subpatterns)
                match = re.search(pattern, line)
                print '  ', match.groupdict()

Regards,
Ganesh



More information about the Python-list mailing list