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 for Beginners
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
Devops Lab | 60
Python Basics • 28min
0 / 7 lessons complete
Section Overview
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!
Text | 5 min
Python Operators
Text | 4 min
Section Review
Quiz | 5 min
Python Variables • 41min
0 / 8 lessons complete
Section Overview
Text | 4 min
Casting
Text | 4 min
Strings
Text | 5 min
Booleans
Text | 8 min
User Input
Text | 2 min
Numbers
Text | 7 min
NoneType
Free Preview Lesson
Text | 5 min
Assignment: Write a Mad Libs Script
Text | 6 min
Even more Python Variables! • 41min
0 / 6 lessons complete
Python Lists
Text | 8 min
Python Tuples
Text | 7 min
Python Sets
Text | 7 min
Frozensets
Text | 6 min
Dictionaries
Text | 8 min
Iterator and Iterable
Text | 5 min
Conditional Statements • 15min
0 / 3 lessons complete
Writing Functions • 30min
0 / 5 lessons complete
Section Overview
Text | 3 min
Defining Functions
Text | 4 min
Importing functions from another file
Text | 4 min
Assignment: Rock, paper, scissors
Text | 12 min
Assignment: Count Dictionary Words
Text | 7 min
Python Loops • 23min
0 / 5 lessons complete
Section Overview
Text | 2 min
For In Loops
Text | 5 min
While Loops
Text | 5 min
Nested Loops
Text | 3 min
Python Loops Challenge!
Text | 8 min
Python PIP and Modules • 18min
0 / 4 lessons complete
Section Overview
Text | 3 min
Installing Python PIP
Text | 4 min
Installing Modules with PIP
Text | 5 min
Importing Modules
Text | 6 min
RegEx • 26min
0 / 4 lessons complete
Working with APIs • 12min
0 / 3 lessons complete
Course Conclusion • 2min
0 / 1 lessons complete