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

  • SEARCH
  • Home
  • 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 8747439
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:21:21+00:00 2026-06-13T12:21:21+00:00

I got a good email vaidation regex from: Email regular expression public static void

  • 0

I got a good email vaidation regex from:
Email regular expression

    public static void Main(string[] args)
    {
        string value = @"cvcvcvcvvcvvcvcvcvcvcvvcvcvcvcvcvvccvcvcvc";
        var regex = new Regex(
            @"^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})$",
            RegexOptions.Compiled);
        var x = regex.Match(value); // Hangs here !?!
        return;
    }

It works in most cases, but the code above hangs, burning 100% CPU… I’ve tested in a W8 metro App. and on a standard .Net 4.5 app.

Can anyone tell me why this happens, and if there is a good email validation REGEX that doesn’t hang, or if there is a way to fix this one?

Many thanks,
Jon

  • 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-06-13T12:21:22+00:00Added an answer on June 13, 2026 at 12:21 pm

    The explanation why it hangs: Catastrophic backtracking.

    Let’s simplify the crucial part of the regex:

    (\w*[0-9a-zA-Z])*@
    

    You have

    • an optional part \w* that can match the same characters as the following part [0-9a-zA-Z], so the two combined translate, in essence, to \w+
    • nested quantifiers: (\w+)*

    This means that, given s = "cvcvcvcvvcvvcvcvcvcvcvvcvcvcvcvcvvccvcvcvc", this part of the regex needs to check all possible permutations of s (which number at 2**(len(s)-1)) before deciding on a non-match when the following @ is not found.

    Since you cannot validate an e-mail address with any regex (there are far too many corner cases in the spec), it’s usually best to

    • do a minimal regex check (^.*@.*$)
    • use a parser to check validity (like @Fake.It.Til.U.Make.It suggested)
    • try and send e-mail to it – even a seemingly valid address may be bogus, so you’d have to do this anyway.

    Just for completeness, you can avoid the backtracking issues with the help of atomic groups:

    var regex = new Regex(
        @"^([0-9a-zA-Z](?>[-.\w]*[0-9a-zA-Z])*@(?>[0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})$",
        RegexOptions.Compiled);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a CSS related question, I got one good answer from my previous
Good morning, I got a class DirObserver with a custom event: public EventHandler<FileDetectedEventArgs> NewFileDetected;
Is this code a good fit for the strategy pattern? public function isValidEmail($email, $organization)
I have read a good bit on the limitations of sending html email from
I, like many developers, got an email from Apple recently that stated we should
Anyone got a good handle on a barcode scanning library that can be used
Anyone got some good references for targeting web content to the iPad web browser?
Hi guys i previously asked a question and got a good solution. here is
Since my AS3 and Php/Java knowledge is not good I got stuck on this
I got a question about good practice. I'm making a simple game and, I'm

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.