Project: pull out the emails
JavaScript · Unit 17: What JavaScript brings along
- Full plan
- JavaScript
- Project
- 3 exercises
An email looks like this: name@site.com. With what you learned here you can describe it: \w+, the at sign, \w+, a dot and another \w+.
The dot goes in as \., because a loose dot means "any character".
const p = /\w+@\w+\.\w+/;
console.log(p.test("ava@mail.com"));
console.log(p.test("avamail.com"));Prints
true false
Exercises in this lesson
You do them in the app, which checks them on the spot and explains why.
1. Complete the code
Fill in the blank in
emailOk, which accepts the text only if it's a whole email and nothing else.2. Write the code
Write
emails(text): an array with every email that shows up in the text, in the order they appear. If there are none, an empty array. Remember thegflag, and thatmatchcan givenull.3. Write the code
Write
domains(text): the sites of the emails in the text, with no repeats and in the order they appear. Forava@mail.comthe domain ismail.com. Thefoundarray already carries the emails.
It opens in your browser. This lesson is part of the full plan; the first unit of each course is free.