Skip to main content

Regular Expressions: Parsing Mailing List Data

Hands-On Lab

 

Photo of Elle Krout

Elle Krout

Content Team Lead in Content

Length

00:30:00

Difficulty

Intermediate

Many regex engines also include the ability to create basic if-then-else statements, setting it so certain parts of the expression only match if specific parameters are met, allowing us to use a single expression to match a variety of options; this allows us more flexibility in how we write and use our expressions.

What are Hands-On Labs?

Hands-On Labs are scenario-based learning environments where learners can practice without consequences. Don't compromise a system or waste money on expensive downloads. Practice real-world skills without the real-world risk, no assembly required.

Regular Expressions: Parsing Mailing List Data

Introduction

Many regex engines also include the ability to create basic if-then-else statements, setting it so certain parts of the expression only match if specific parameters are met, allowing us to use a single expression to match a variety of options; this allows us more flexibility in how we write and use our expressions.

Solution

Begin by logging in to the lab server using the credentials provided on the hands-on lab page:

ssh cloud_user@PUBLIC_IP_ADDRESS

Match the "From:" data:

grep -Po 'From: w+ <w+@w+.w{2,63}>' emaillist.mbox

Match the "Subject:" data:

grep -Po 'Subject: .+' emaillist.mbox

Combine the two searches and save the data to mailing-list-report.txt:

grep -Po '((From)|Subject): (?(2)w+ <w+@w+.w{2,63}>|.+)' emaillist.mbox > mailing-list-report.txt

Conclusion

Congratulations — you've completed this hands-on lab!