Project: pull out the emails
Python · Unit 18: Regular expressions
- Full plan
- Python
- Project
- 3 exercises
You're going to work with emails. The rule for this project: an email is \w+, an at sign, \w+ and .com.
The dot is written \. to ask for a real dot and not for any character. A real validator is longer; this one is enough to learn with.
import re
p = r"\w+@\w+\.com"
t = "amy@mail.com"
print(bool(re.fullmatch(p, t)))Prints
True
Exercises in this lesson
You do them in the app, which checks them on the spot and explains why.
1. Complete the code
is_emailshould accept only emails ending in .com. Complete the pattern.2. Write the code
Write
extract(t): it gives back the list of emails in the text, in the order they show up. If there are none, the list comes back empty. Use the same email rule as the step before.3. Write the code
Write
censor(t): it gives back the same text, but with every email swapped for***. If there are no emails, the text comes out unchanged. The pattern is already written.
It opens in your browser. This lesson is part of the full plan; the first unit of each course is free.