title: Exponential Regex Problem
body: <p>Can someone help me rewrite this regex to be non-exponential?</p>
  
  <p>I'm using perl to parse email data. I want to extract email addresses from the data. Here is  a shortened version of the regex that I've been using:</p>
  
  <p><code>my $email_address = qr/(?:[^\s@&lt;&gt;,":;\[\]\(\)\\]+?|"[^\"]+?")@/i</code></p>
  
  <p>For simplicity I've removed the later domain part of the regex. (It isn't causing any problems.)</p>
  
  <p>This will find an RFC compliant email address that either contains non-email meta chars OR a "quoted" string followed by @. Using the OR '|' part of the regex with the two different multicharacter patterns creates an exponential problem.</p>
  
  <p>The problem is, when I unleash this on a line of data that is several thousands of characters long.</p>
  
  <pre><code>$ wc line7.txt 
  1    221 497819 line7.txt
  </code></pre>
  
  <p>(I'm sorry but I cannot provide input data at this time, I may be able to mock some up later.)</p>
  
  <p>Much like rewriting (a*b*)* to (a|b)*, I need to rewrite this regex. </p>
  
  <p>Splitting it into two separate regex's creates more work in code changes then I am willing to perform at this point. Although it would solve my problem.</p>
  
  <p>The eventual target machine is on a Hadoop cluster. So I would like to avoid CPAN modules that don't come with Hadoop's version of perl. (I'll have to check if Email::Find can even be used.) This is a problem I encountered at work.</p>