Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6045395
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:07:12+00:00 2026-05-23T07:07:12+00:00

Can someone help me rewrite this regex to be non-exponential? I’m using perl to

  • 0

Can someone help me rewrite this regex to be non-exponential?

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:

my $email_address = qr/(?:[^\s@<>,":;\[\]\(\)\\]+?|"[^\"]+?")@/i

For simplicity I’ve removed the later domain part of the regex. (It isn’t causing any problems.)

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.

The problem is, when I unleash this on a line of data that is several thousands of characters long.

$ wc line7.txt 
1    221 497819 line7.txt

(I’m sorry but I cannot provide input data at this time, I may be able to mock some up later.)

Much like rewriting (a*b*)* to (a|b)*, I need to rewrite this regex.

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.

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T07:07:12+00:00Added an answer on May 23, 2026 at 7:07 am
    qr/(?:(?>[^\s@<>,":;\[\]\(\)\\])+|"[^\"]{0,62}")@/i
    

    The (?>expression) part prevents backtracking. It should be safe because there can be no overlap between the non-quoted part and the quoted part.

    I removed the lazy repeats +? because the parts of the alternation already look for the @ and " respectively. Phrases could be a large source of backtracking, so I looked at the Wikipedia article which states that the local part (before the @) can be only 64 characters long (subtracting two quotes yields {0,62} (if ""@ is not valid, then change it to {1,62}…. I do not intend for this to be a completely functional email parser. That is your job. I simply provide help for the catastrophic backtracking.) Best of luck!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can someone help my regex-challenged self with this? The match must start with *.
can someone help me writing an RegEx for Apache Mod Rewrite? i wannt do
Can someone help me achieve multiple zend pagination in a view using ajax. I
Can someone help me understand how to write this case statement properly its not
Can someone help me with creating functions for the following processes? I want to
Can someone help me on how to setup such a result: Want to know
Can someone help me with the correct use of the split function in perl
I can only find mod rewrite examples/tutorials for query's, so can someone help me
I hope someone can help me with this. This is my .htaccess file: RewriteEngine
Can someone help me with this? I'm feeling like I've been hitting my head

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.