title: Regex trouble with list comprehension
body: <p>I am working in Python 3.7.6 on Windows and am attempting to use regex to transform one list of <code>foo.csv.gz</code> filenames into a list of the corresponding <code>foo.csv</code> filenames. A code snippet is below.</p>
  <pre><code>zippedFileNames = [re.search('[^/]*\\.gz', link).group(0) for link in linksList]
  
  unzippedFileNames = [re.search('.*\\.csv', name).group(0) for name in zippedFileNames]
  </code></pre>
  <p>In the above code, <code>zippedFileNames</code> is a list created by isolating the <code>.gz</code> filenames from a list of download links. This line works as I expect, and taking <code>zippedFileNames[0]</code> returns a string. The type of <code>zippedFileNames[0]</code> is <code>str</code> and the type of <code>zippedFileNames</code> is <code>list</code>.</p>
  <p>However, the code throws an error on the second line:</p>
  <pre><code>Exception has occurred: AttributeError
  'NoneType' object has no attribute 'group'
    File &quot;H:\foo\bar\foobar.py&quot;, line 133, in &lt;listcomp&gt;
      x = [re.search('.*\\.csv', name).group(0) for name in zippedFileNames]
    File &quot;H:\foo\bar\foobar.py&quot;, line 133, in &lt;module&gt;
      x = [re.search('.*\\.csv', name).group(0) for name in zippedFileNames]
  </code></pre>
  <p>This code was working yesterday but stopped working today, and I am not sure what I changed to break it. I believe it broke after I tried amending the second line's <code>pattern</code> to omit the  first digits and underscore using the pattern <code>'[^0-9\\_].*\\.csv'</code> (the filenames all follow a pattern <code>0000_foo_bar_foobar.csv.gz</code>). However, even reverting the pattern to the old one before the omission does not solve my problem.</p>
  <p>Is there something I'm not seeing?</p>
  <p>Thank you!</p>
  <p><strong>EDIT:</strong></p>
  <p>Thank you for your answers.</p>
  <p>I checked whether there is a <code>None</code> in my list both by printing all list items and by using <code>print(None in zippedFileNames)</code>. The latter test returned <code>False</code> and the former returned all the items as I'm expecting. I also did not find <code>None</code> in my linksList.</p>
  <p>When I run the regex <code>re.search</code> on just one of the elements of <code>linksList</code>, <code>linksList[0]</code>, I get the correct string output.</p>
  <p>Are there other things I can try?</p>
  <p><strong>EDIT 2:</strong></p>
  <p>I tried re-using the original regex pattern <code>'[^/]*\\.gz'</code> in a separate call and it worked. Then I also tried using the pattern <code>'[^/]*\\.csv\\.gz'</code> in hopes of getting the same result as I got with the former pattern, but this pattern returned an error as well. I'm suspecting that the errors have something to do with <code>\\.csv</code>.</p>
  <p><strong>RESOLUTION</strong>
  I was matching on <code>.csv</code>, but it turned out that I had a <code>.report</code> file as well, and that one was throwing off the entire script. Iterating through matches helped to isolate the issue. To solve the regex, I matched the pattern <code>'.*\\[^.gz]'</code> to keep all file extensions, not just <code>.csv</code>. Thank you very much!!</p>