re.compile only takes two arguments, is there a way to make it take more? Or another way around that?
<p>I am able to access an email in txt file form on my computer, and now my goal is to scrape specific data out of it. I have utilized <code>re.compile</code> and <code>enumerate</code> to parse through the email looking for matching words (in my case, fish species such as GOM Cod), and then printing them. But there are 100's more emails I will need to parse thru, each with several different fish species listed in them....so my question is: what is the best way to go about this? I can't put all 17 different possible fish species into one <code>re.compile</code> function so should I just have 17 different blocks of the same code with just the fish species changed in each? Is that the most efficient way? My code is below. </p>

<pre><code>import os
import email
import re

path = 'Z:\\folderwithemail'

for filename in os.listdir(path):
file_path = os.path.join(path, filename)
if os.path.isfile(file_path):
    with open(file_path, 'r') as f:
        sector_result = []
        pattern = re.compile("GOM Cod", re.IGNORECASE)
        for linenum, line in enumerate(f):
            if pattern.search(line) != None:
                sector_result.append((linenum, line.rstrip('\n')))
                for linenum, line in sector_result:
                    print ("Fish Species:", line)
</code></pre>

<p>You can <em>alternate</em> between fish species using the vertical bar <code>|</code>:</p>

<blockquote>
  <p><code>A|B</code>, where A and B can be arbitrary REs, creates a regular expression
  that will match either A or B</p>
</blockquote>

<pre><code>pattern = re.compile(r"GOM Cod|Salmon|Tuna", re.IGNORECASE)
</code></pre>

python screen-scraping enumerate