FF+Firebug got an error "Regular Expression too complex", IE crashed and Chrome hung
According to this http://www.utexas.edu/its/help/domain-name-hosting-and/847 then I made this regular expression:
/^[a-z](\w+\.?\w*[a-z0-9]){5,17}@[a-z]((a-z0-9\-]{1,25}\.[a-z]{2,4})|([a-z0-9\-]{1,25}\.[a-z]{2,3}\.[a-z]{2,3}))$/;
And th开发者_开发技巧row this value:
asdfghjklzxcvbnmqwertyuiopasdfghjklzxcvbn@yahoo.comFirefox + firebug says "Regular Expression too complex", IE Crashed and Chrome hung, is there something wrong with the regexp?
I use Javascript.
Missing [
/^[a-z](\w+\.?\w*[a-z0-9]){5,17}@[a-z]((
here [
a-z0-9\-]{1,25}\.[a-z]{2,4})|([a-z0-9\-]{1,25}\.[a-z]{2,3}\.[a-z]{2,3}))$/;
Try this (your solution has misprint):
^[a-z](\w+\.?\w*[a-z0-9]){5,17}@[a-z](([a-z0-9\-]{1,25}\.[a-z]{2,4})|([a-z0-9\-]{1,25}\.[a-z]{2,3}\.[a-z]{2,3}))$
I think you forgot [
in (a-z0-9\-]{1,25}
The actual issue here (ignoring the missing [
) is that you have a greedy qualifier (/w+
and /w*
) following by a range ({5,17}
)
What this means is:
- find any number of
\w
characters - filter down to 5-17
The engine only does the filter after it finds the "any number", and gets very confused here...
It's a weird expression anyway: (\w+\.?\w*[a-z0-9]){5,17}
The {5,17}
should almost certainly be on part of that, not the entire thing.
what if someone has email address like john.doe@media.company.info or jane.doe@company.office?
try this:
(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])
http://regexpal.com/
精彩评论