Advanced Lesson 1
Regular Expressions
Chapter 5: Exercises
Email address parser
Task 4: Email address parser
A final applied task: develop a regular expression to validate a given email address.
For simplicity, we will use these rules:
- An email address is in the form
USER@HOST.EXT USERcan be made up of one or more uppercase or lowercase letters, digits, underscores, dots (.),+,?and-.HOSTcan be made up of one or more uppercase or lowercase letters, digits, or a hyphen (-). It must not end with a hyphen (-), and must not be made up of only digits.EXTcan be eitherco,com, ororg.
Stress test your regular expression with good and bad cases.
Hint: break down the problem into smaller subproblems! Tackle EXT first, then USER, then HOST.