title: Converting Perl Regex Statement to Python Regex
body: <p>I need to convert some regex from perl to python, but I am not that familiar with perl regex.</p>
  
  <p>I have the following:</p>
  
  <pre><code>$x =~ s/([^\"])(item\s+7[^0-9a-z\"]*management(?:[^0-9a-z]{0,3}s)?\s+discussions?\s+and\s+analysis\s+of\s+(?:financial\s+conditions?\s+|results\s+of\s+operations?)(?:\s+and\s+results\s+of\s+operations?|\s+and\s+financial\s+conditions?)?)/\1#######ITEM7:\2#######/gis;
  
  $x =~ s/([^\"])(item\s+7[^0-9a-z\"]*a[^0-9a-z\"]*(?:quantitative\s+and\s+(?:qualitative|qualification)\s+disclosures?\s+about\s+)?market\s+risk)/\1#######ITEM7A:\2#######/gis;
  
  $x =~ s/([^\"])(item\s+8[^0-9a-z\"]*.{0,40}financial\s+statements[^\.])/\1#######ITEM8:\2#######/gis;
  
  @X = (split /\#\#\#\#\#\#\#/, $x)
  </code></pre>
  
  <p>I believe that <code>s/</code> is equivalent to python <code>re.split</code> but I'm not sure what <code>/gis</code> does though.</p>
  
  <p>Also, I am not sure what this means either:</p>
  
  <pre><code>(@M) = ($y =~ m/((?:\d+:ITEM7 \d+:\d+ )+(?:\d+:ITEM7A \d+:\d+ )*)(?:\d+:ITEM8 \d+:\d+\s*)+/g)
  </code></pre>
  
  <p>I would greatly appreciate the help !</p>
  
  <p>EDIT: </p>
  
  <p>Just another quick question, what exactly does:</p>
  
  <pre><code>for($i = 0; $i &lt; scalar(@X); ++$i) {
    if($X[$i] =~ m/^(ITEM(?:7|7A|8)):(.*)$/s) {
      $Z[$i] = $2; 
      $Y[$i] = $i . ':' . $1; 
    } else {   
      $Z[$i] = $X[$i]; 
      $Y[$i] = $i . ':' . length_in_words($X[$i]);  
    }
  }
  
  sub length_in_words {
    my $x = shift;
    my @k;
    return scalar(@k = $x =~ m/(\S+)/sg);
  }
  </code></pre>