More Basic Regular Expressions: Matching an Email Address

30 minutes
  • 2 Learning Objectives

About this Hands-on Lab

As our knowledge and experience with regular expressions grows, we can begin to match more and more generalized items, such as an email address. By coming up with the regex to match an email address, we need to use concepts such as grouping, ranges, repetition, literal characters, and more. This learning activity also expects you to have some knowledge of `grep` and `sort`.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Create an `emails.txt` file.

Create an emails.txt file containing an ordered list of all customer emails.

Match all emails in `customer-data.txt`.

Use grep and a regular expression to match all the emails in the customer-data.txt file.

Additional Resources

You work for Ethercloud, a web hosting company. Due to scheduled downtime, the support team needs a list of email addresses so that they can contact customers appropriately. Since you have access to a CSV of customer data (customer-data.xt), you've been tasked with retrieving all emails from this data via regular expression and sorting them in alphabetical order. (Hint: Use grep and sort.)

While writing the regular expression, note the following restrictions regarding email address:

  • The local-part (or username), can use any alphanumeric character or one of the following: <code>! # $ % & ' * + - / = ? ^ _ ` { | } ~ .</code>
  • The second-level domain (gmail in must begin with an alphanumeric character but any character after that can also contain a dash (-).
  • The domain must be at least one character long.
  • The top-level domain (such as com) must only use alphanumeric characters.
  • The top-level domain must be between two and 63 characters.

If you need a list of email addresses to match, try:

What are Hands-on Labs

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Sign In
Welcome Back!

Psst…this one if you’ve been moved to ACG!

Get Started
Who’s going to be learning?