Sneaky O(log n) in email validation regex.

Sneaky bad code. I was applying to a job and had to log in to the job board site. Their email input started stalling out as I typed in my unreasonably long email, so I started digging because I am bored and unemployed.

Breakdown for anyone who's learning.

The regex:

^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{1,3})+$  

Here it is broken down

What they want: Email must always start with at least one \w word character (A-Z a-z 0-9 _)
After that, you can get . or - symbols, followed by more word symbols as possible.

The problem: The ? after [.-] says that those are optional. So what they end out getting is 'find me one or more word symbols, followed by one or more word symbols, followed by one or more symbols...) repeating indefinitely.

So it will break 'abc' down into this set: [abc, a bc, ab c, a b c].
For 'abcd' [abcd, a bcd, ab cd, abc d, a b cd, a bc d, ab c d, a b c d]
and will get increasingly complex with each additional character added.

/r/badcode Thread Link - gist.github.com