title: Renumbering line by line
body: <p>I have an input text which looks like this:</p>
  
  <pre><code>word77 text text bla66 word78 text bla67
  text bla68 word79 text bla69 word80 text
  bla77 word81 text bla78 word92 text bla79 word99
  </code></pre>
  
  <p>I have to renumber <code>word</code> and <code>bla</code>  from 1, in each line.</p>
  
  <p>I can renumber the whole input which looks like this:</p>
  
  <pre><code>word1 text text bla1 word2 text bla2
  text bla3 word3 text bla4 word4 text
  bla5 word5 text bla6 word6 text bla7 word7
  </code></pre>
  
  <p>The code for the above:</p>
  
  <pre><code>import re
  def replace(m): global i; i+=1; return str(i);
  fp = open('input.txt', 'r').read()
  i = 0
  fp = re.sub(r'(?&lt;=word)(\d+)', replace, fp)
  i = 0
  fp = re.sub(r'(?&lt;=bla)(\d+)', replace, fp)
  #open('sample.txt', 'wb').write(fp)
  print fp
  </code></pre>
  
  <p>Ideally, the result should look like this:</p>
  
  <pre><code>word1 text text bla1 word2 text bla2
  text bla1 word1 text bla2 word2 text
  bla1 word2 text bla3 word3 text bla4 word4
  </code></pre>