Regex Challenge!

Welcome to the "Regex Challenge" lesson! In this exciting lesson, we'll put your Regex skills to the test by tackling two challenging problems. Each problem will require you to apply the concepts and techniques learned in the previous lessons to construct complex Regex patterns and solve real-world scenarios. Let's dive in and sharpen your Regex prowess!

Throughout this lesson, you'll encounter a variety of problem scenarios that require different Regex patterns to solve. For each problem, you'll be provided with a description and an example string. Your task is to design a Regex pattern that matches the desired pattern or extracts specific information from the given string.

Challenge #1:

You are given a list of email addresses. Your task is to extract all the unique domain names from the string of emails. Copy the code below into the Python IDE and update the pattern variable so that it outputs all of the domain names in the string.

import re

email_list = """
john.doe@example.com
jane.smith@example.com
james.brown@example.net
alice.walker@example.net
"""

# Your Regex pattern and solution here
pattern="insert your regex pattern here"

unique_domains = set(re.findall(pattern, email_list))
print(unique_domains)

The output should be as shown below:

{'example.net', 'example.com'}

If you get stuck, you can check out the solution below:

Challenge #1 Solution

Challenge #2:

Your objective is to extract all the hashtags from a given tweet. Copy the code below into the Python IDE and update the pattern variable so that it outputs all of the hashtags in the string.

import re

tweet = """
Celebrating the #NationalDonutDay with my friends! #DonutsAreLife #FridayFeeling
"""

# Your Regex pattern and solution here
pattern = "insert your regex pattern here"

hashtags = re.findall(pattern, tweet)
print(hashtags)

Your result should look like this:

['#NationalDonutDay', '#DonutsAreLife', '#FridayFeeling']

If you're struggling, check out the solution below:

Challenge Solution

Challenge #2 Solution


Server Academy Members Only

Want to access this lesson? Just sign up for a free Server Academy account and you'll be on your way. Already have an account? Click the Sign Up Free button to get started..

0 0 votes
Lesson Rating
Subscribe
Notify of
profile avatar
0 Comments
Inline Feedbacks
View all comments

Saving Progress...

Sign up for free!

Sign up for free and get instant access to this course!.

Python 3 for Beginners

0%

0/1 Lessons

Installing Python on Windows

• 1hr 17min

0 / 4 lessons complete

Python Basics

• 28min

0 / 7 lessons complete

Python Variables

• 41min

0 / 8 lessons complete

Even more Python Variables!

• 41min

0 / 6 lessons complete

Conditional Statements

• 15min

0 / 3 lessons complete

Writing Functions

• 30min

0 / 5 lessons complete

Python Loops

• 23min

0 / 5 lessons complete

Python PIP and Modules

• 18min

0 / 4 lessons complete

RegEx

• 26min

0 / 4 lessons complete

Working with APIs

• 12min

0 / 3 lessons complete

Course Conclusion

• 2min

0 / 1 lessons complete