This is an archived version of the course. Please find the latest version of the course on the main webpage.

Chapter 5: Exercises

Email address parser

face Josiah Wang

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
  • USER can be made up of one or more uppercase or lowercase letters, digits, underscores, dots (.), +, ? and -.
  • HOST can 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.
  • EXT can be either co, com, or org.

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.