Write a regular expression which matches a email address

Answer: This is very tricky question. Matching emails is not as trivial as it seems and the answer can be as simple as


or as messy as


Remember, it is interview question, not production code. So, be simple. I always recommend starting with basics:


Then explain its limitations and give couple examples there the pattern would give false positive or false negative results. (such as test@test.111). From my experience, usually it is more than enough to impress interviewer. From the other side, you always can iteratively enhance this pattern engaging interviewer into the conversation giving you the chance to showcase your knowledge.

Another popular question is also about parsing HTML

Answers and Comments