I'm setting up a little function to run a configurable regex list over a line, so far I have two regexs, but it seems to only be executing one of the patterns associated with the regex, here's my code.
def run_all_regex(self, line):
regexp: {
'regex1' : 'complicated regex',
'regex2' : 'complicated regex2',
}
for key, pattern in regexp.iteritems():
m = match(pattern, line)
if m:
x = line
else:
x = None
return x
I added a print statement after my for, key... line to see what patterns were being printed over, and it was only the second one! After I removed the second one, the first one printed! What gives?
EDIT:
So I've seen that my return statement has bogged up my function, I'd like to elaborate on what I'm trying to do here.
Basically I am opening a file, reading it line by line, and for each line running this function that will run the two (so far) regexes on the line, and if that line matches either regex, return it to a key in a dict. Here's the code.
for key in dict:
with open(key) as f:
for line in f:
dict[key] = self.run_all_regex(line)
So at the end of it all, dict[key] should be a line that matches the regex that I have in the run_all_regex section.