How to substitute several regex in Python? : <p>I would like to loop on every lines from a .txt file and then use <code>re.sub</code> method from Python in order to change some contents if there is a specific pattern matcing in this line.</p>

<p>But how can I do that for two different pattern in the same file ?</p>

<p>For example, here's my code :</p>

<pre><code>file = open(path, 'r')
output = open(temporary_path, 'w')

for line in file:
    out = re.sub("patternToChange", "patternToWrite", line) #Here I would like to also do the same trick with "patternToChange2 and patternToWrite2 also in the same file
    output .write(out)
</code></pre>

<p>Do you have any ideas ?</p>
