I am trying to match the expressions "ephname" below (depending on the file that is present), but I want the numbers to be captured:
entries = ['other data\nephdelay = 12\nephname = cfghjk78.comb\nother data', 'other data\nephdelay = 17\nephname = qwerty.s92\nother data']
I use this as my regular expression, but there are no matches (however, it only works for one if I select one and delete the boolean):
\s?ephname\s?=\s?.*?\.s(\d+)\s?|\s?ephname\s?=\s?.*?(\d+)\.comb\s?
I tested this on regex websites and I don't understand what the problem is. I want the output to be either "94" or "78" depending on the record. Why am I not getting any matches?
Edit: In my code, I have this:
import re
commonterms = (["term1", "#term1pattern"],
["ephsol", "\s?ephname\s?=\s?.*?\.s(\d+)\s?|\s?ephname\s?=\s?.*?(\d+)\.comb\s?"],
["term3", "#term3pattern"], ...)
terms = [commonterms[i][0] for i in range(len(commonterms))]
patterns = [commonterms[i][1] for i in range(len(commonterms))]
d = {t: [] for t in terms}
def getTerms(entry):
for i in range(len(terms)):
term = re.search(patterns[i], entry)
term = term.groups()[0] if term else 'NULL'
return d
for entry in entries:
d = getTerms(entry)
print d['ephsol']
Then when I print d['ephsol'], I just get a bunch of NULL, but I know there should be matches.