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 me on this. I'm made an image uploader and i want
can someone help me writing an RegEx for Apache Mod Rewrite? i wannt do
Can someone help me identify what the purpose of this unidentified syntax is. It
Can someone help me with this: This is a program to find all the
Can someone help me create an index/count button for a UITableView, like this one?
can someone help with this? I need the following function to do this... $x
I can only find mod rewrite examples/tutorials for query's, so can someone help me
Can someone help me explain what is happening here? Sorry if this is a
Can someone help me to see what is going wrong with this setup I
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.