-4

Can anybody please have a look at
https://regex101.com/r/ApWCG0/1
and correct the regex so that it doesn't give timeout or doesn't cause infinite loop ?
I have been testing it in nodejs and getting an infinite loop and getting in timeout in Regex testing websites.
I have been searching for it for a while on stackoverflow and other websites but couldn't find it. Sorry, if this thread has a duplicate.

my email regex is [a-zA-Z0-9_\-.]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-.]+

Hope somebody get through this.

Update:
[a-zA-Z0-9_\-.]{2,64}@[a-zA-Z0-9\-]{2,64}\.[a-zA-Z0-9\-.]{2,64}
This is covering most cases. I am just restricting the number of characters.

Vikas Gautam
  • 1,793
  • 22
  • 21
  • just go here: http://emailregex.com/ – garglblarg Dec 07 '16 at 12:29
  • @garglblarg ok, I am watching that, but could you explain why is that giving timeout or infinite loop ? – Vikas Gautam Dec 07 '16 at 12:32
  • @garglblarg I tried [http://emailregex.com/email-extractor-tool/](http://emailregex.com/email-extractor-tool/) website with the same content to extract emails from, but this goes in infinite loop. Any idea what would work in this case ? – Vikas Gautam Dec 07 '16 at 12:42
  • in this case i suspect that it's not a wrong regex but invalid input _or_ it's not really an infinite loop but just taking very very long which would look the same, i dunno. – garglblarg Dec 07 '16 at 12:44
  • ok, I got you, I will see. – Vikas Gautam Dec 07 '16 at 12:47
  • Possible duplicate of [Using a regular expression to validate an email address](http://stackoverflow.com/questions/201323/using-a-regular-expression-to-validate-an-email-address) – Mark van Straten Dec 07 '16 at 12:52

2 Answers2

1

I checked your regular expression and found out that if we pass single word[which has extremely high character length] then regular expression fail to check and give timeout error.

E.g: https://regex101.com/r/sjvQ7Z/1

And when I removed that word from your test string then your expresion is working fine.

E.g: https://regex101.com/r/lszdaL/1

vijay
  • 731
  • 5
  • 15
  • I agree with you sir. but I don't have any control over the input so came up with this `[a-zA-Z0-9_\-.]{2,64}@[a-zA-Z0-9\-]{2,64}\.[a-zA-Z0-9\-.]{2,64}`. The points you have mentioned are the exact words for the problem. I appreciate that. It helped! – Vikas Gautam Dec 07 '16 at 14:19
0

You experienced catastrophic backtracking because of the Chat Data dump that contained 943k characters. Just remove it and it'll work fine.

Graham
  • 7,431
  • 18
  • 59
  • 84
Thomas Ayoub
  • 29,063
  • 15
  • 95
  • 142