Find and remove specific string from a line
<p>I am hoping to receive some feedback on some code I have written in Python 3 - I am attempting to write a program that reads an input file which has page numbers in it. The page numbers are formatted as: "[13]" (this means you are on page 13). My code right now is:</p>

<pre><code>pattern='\[\d\]'

for line in f:
if pattern in line:
    re.sub('\[\d\]',' ')
    re.compile(line)
    output.write(line.replace('\[\d\]', ''))
</code></pre>

<p>I have also tried:</p>

<pre><code>for line in f:
    if pattern in line:
    re.replace('\[\d\]','')
    re.compile(line)
    output_file.write(line)
</code></pre>

<p>When I run these programs, a blank file is created, rather than a file containing the original text minus the page numbers. Thank you in advance for any advice!</p>