I have an odd problem occurring with our regex for email addresses. Here is the expression:
^(\w)+(([(\.?)\w\-+])*[\w]+)*@((\[([\d]{1,3}\.){3}[\d]{1,3}\])|((\w)+((\.?)[\w\-]+)*\.[a-z]{2,6}))$
Anything we've thrown at it which matches is fine, the problem is with failures, long strings cause the expression to hang. On our webserver it will spike the CPU. Some examples follow. The problem is when people enter long email addresses errantly, it crashes the server.
This is a failure which works.
rubular failure 1 short@failure
This is a failure which causes the hanging, you can see rubular has issues as well.
rubular failure 2 thisisamuchlonger@expressionleadingtofailure
The interesting thing is if you make it proper:
rubular pass [email protected]
This passes easily.
Edit: A note, I've also attempted to run this using the client side javascript tester and it will fail/succeed in the same ways. There is something about this regex which causes parsers to eat memory and fail, I'm just not sure what part it is.
\Aand\zinstead of^and$.