#!/usr/bin/python import re a=open("R7.Mail.php").readlines() b=re.compile("MODEM: 422") c=[] for i,v in enumerate(a): if b.findall(v): c[len(c):] = [a[i+3]] d=re.compile(">.*?<") e=[] g = re.compile(' ') for f in c: tmp = d.findall(c[2])[2][1:-1] e[len(e):] = [g.sub("", tmp)] print e[0]