Regex Challenge!
Server Academy Members Only
Sorry, this lesson is only available to Server Academy members. Create a free account now to get instant access to this and more free courses. Click the Sign Up Free button below to get access to our free courses now, or sign in if you have an account.
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..
Saving Progress...
Python 3 Fundamentals
Installing Python on Windows • 1hr 17min
0 / 4 lessons complete
Section Overview
Free Preview Lesson
Text | 1 min
Downloading and Installing Python on Windows
Free Preview Lesson
Text | 8 min
Installing and configuring VS Code for Python
Free Preview Lesson
Text | 8 min
Lab: Installing Python
Free Preview Lesson
Devops Lab | 60
Python Basics • 28min
0 / 7 lessons complete
Section Overview
Free Preview Lesson
Text | 2 min
Executing Python Code
Free Preview Lesson
Text | 3 min
Python 3 Syntax
Free Preview Lesson
Text | 5 min
Help! Python Keywords
Free Preview Lesson
Text | 4 min
Printing to the console!
Free Preview Lesson
Text | 5 min
Python Operators
Free Preview Lesson
Text | 4 min
Section Review
Free Preview Lesson
Quiz | 5 min
Python Variables • 41min
0 / 8 lessons complete
Section Overview
Free Preview Lesson
Text | 4 min
Casting
Free Preview Lesson
Text | 4 min
Strings
Free Preview Lesson
Text | 5 min
Booleans
Free Preview Lesson
Text | 8 min
User Input
Free Preview Lesson
Text | 2 min
Numbers
Free Preview Lesson
Text | 7 min
NoneType
Free Preview Lesson
Text | 5 min
Assignment: Write a Mad Libs Script
Free Preview Lesson
Text | 6 min
Even more Python Variables! • 41min
0 / 6 lessons complete
Python Lists
Free Preview Lesson
Text | 8 min
Python Tuples
Free Preview Lesson
Text | 7 min
Python Sets
Free Preview Lesson
Text | 7 min
Frozensets
Free Preview Lesson
Text | 6 min
Dictionaries
Free Preview Lesson
Text | 8 min
Iterator and Iterable
Free Preview Lesson
Text | 5 min
Conditional Statements • 15min
0 / 3 lessons complete
Section Overview
Free Preview Lesson
Text | 2 min
If Statements
Free Preview Lesson
Text | 6 min
Try, Except
Free Preview Lesson
Text | 7 min
Writing Functions • 30min
0 / 5 lessons complete
Section Overview
Free Preview Lesson
Text | 3 min
Defining Functions
Free Preview Lesson
Text | 4 min
Importing functions from another file
Free Preview Lesson
Text | 4 min
Assignment: Rock, paper, scissors
Free Preview Lesson
Text | 12 min
Assignment: Count Dictionary Words
Free Preview Lesson
Text | 7 min
Python Loops • 23min
0 / 5 lessons complete
Section Overview
Free Preview Lesson
Text | 2 min
For In Loops
Free Preview Lesson
Text | 5 min
While Loops
Free Preview Lesson
Text | 5 min
Nested Loops
Free Preview Lesson
Text | 3 min
Python Loops Challenge!
Free Preview Lesson
Text | 8 min
Python PIP and Modules • 18min
0 / 4 lessons complete
Section Overview
Free Preview Lesson
Text | 3 min
Installing Python PIP
Free Preview Lesson
Text | 4 min
Installing Modules with PIP
Free Preview Lesson
Text | 5 min
Importing Modules
Free Preview Lesson
Text | 6 min
RegEx • 26min
0 / 4 lessons complete
Working with APIs • 12min
0 / 3 lessons complete
Course Conclusion • 2min
0 / 1 lessons complete