I'm in-place editing a file using fileinput as below.
for line in fileinput.input():
line = re.sub(pattern1, repl1, line)
line = re.sub(pattern2, repl2, line)
print(line, end="")
I want to apply re.sub only once for each line. If first pattern matches and replaced, I don't need to inspect pattern2.
How do I codify it?