I have a big file. And I have n regexes.
I want to match all n regexes against the file but by going over the file only once. So here is my pseudo code:
Here I run the loop for all regexes for every line.
f = open("file.txt")
for line in f:
for regex in regexes:
m = re.search(regex, line)
if m is not None:
# do something
Another pseudo code, where I write n if-elif
statements
f = open("file.txt")
for line in f:
if re.search(regex1, line)
# do something1
elif re.search(regex2, line)
# do something2
elif re.search(regex3, line)
# do something3
...
else:
pass
I don't like either approaches. What is a better way to do this in python?