title: Regex translation from Perl to Python
body: <p>I would like to rewrite a small Perl programm to Python.
  I am processing text files with it as follows:</p>
  
  <p>Input:</p>
  
  <pre><code>00000001;Root;;
  00000002;  Documents;;
  00000003;    oracle-advanced_plsql.zip;file;
  00000004;  Public;;
  00000005;  backup;;
  00000006;    20110323-JM-F.7z.001;file;
  00000007;    20110426-JM-F.7z.001;file;
  00000008;    20110603-JM-F.7z.001;file;
  00000009;    20110701-JM-F-via-summer_school;;
  00000010;      20110701-JM-F-yyy.7z.001;file;
  </code></pre>
  
  <p>Desired output:</p>
  
  <pre><code>00000001;;Root;;
  00000002;  ;Documents;;
  00000003;    ;oracle-advanced_plsql.zip;file;
  00000004;  ;Public;;
  00000005;  ;backup;;
  00000006;    ;20110323-JM-F.7z.001;file;
  00000007;    ;20110426-JM-F.7z.001;file;
  00000008;    ;20110603-JM-F.7z.001;file;
  00000009;    ;20110701-JM-F-via-summer_school;;
  00000010;      ;20110701-JM-F-yyy.7z.001;file;
  </code></pre>
  
  <p>Here is the working Perl code:</p>
  
  <pre><code>#filename: perl_regex.pl
  #/usr/bin/perl -w
  while(&lt;&gt;) {                                                           
    s/^(.*?;.*?)(\w)/$1;$2/;                                            
    print $_;                                                           
  }      
  </code></pre>
  
  <p>It call it from the command line: <code>perl_regex.pl input.txt</code></p>
  
  <p>Explanation of the Perl-style regex:</p>
  
  <pre><code>s/        # start search-and-replace regexp
    ^       # start at the beginning of this line
    (       # save the matched characters until ')' in $1
      .*?;  # go forward until finding the first semicolon
      .*?   # go forward until finding... (to be continued below)
    )
    (       # save the matched characters until ')' in $2
      \w    # ... the next alphanumeric character.
    )
  /         # continue with the replace part
    $1;$2   # write all characters found above, but insert a ; before $2
  /         # finish the search-and-replace regexp.
  </code></pre>
  
  <p>Could anyone tell me, how to get the same result in Python? Especially for the $1 and $2 variables I couldn't find something alike.</p>