Regular Expressions in Python
Learn to clean, format and search text in Python, then write regular expressions with groups, backreferences and lookaround on real tweets and reviews.
You learn to detect, extract, replace and match the parts of a string you need with regular expressions in Python. The work happens on messy text such as movie reviews, streamed tweets and pages scraped off the web, where cleaning strings and pulling out key details is a step that comes before any machine learning on the data. Along the way you also split, join and interpolate strings with Python’s built-in tools.
What You Will Achieve
- Clean and normalize text reviews by adjusting case, stripping stray spaces and swapping out unwanted words
- Insert values into report text and pick the formatting approach that suits the task
- Write patterns that pull numbers, email addresses and file names out of raw tweets and text
- Filter phone numbers, catch repeated characters and check that tags close properly using grouped patterns
Program Overview
Core String Manipulation
Basic operations practiced on a movie review dataset, covering how strings are cut, combined, cleaned and searched.
- Slicing, concatenating and palindromes
- Adjusting case and removing spaces
- Joining strings and splitting lines
- Finding and replacing substrings
String Formatting Approaches
Three ways to place values inside strings, tried on text scraped off the web and weighed for their advantages and disadvantages.
- Positional formatting and named placeholders
- Formatted string literals
- The Template method
- Preparing a report and identifying prices
Regular Expression Syntax and Advanced Pattern Matching
Pattern matching on tweets meant for sentiment analysis, followed by grouping, backreferences and lookaround for more complex matches.
- Metacharacters, repetitions and splitting on matches
- Greedy versus lazy quantifiers
- Capturing groups, non-capturing groups and alternation
- Backreferences and lookaround
Certificate Awarded (Paid)
Job Outlook
Cleaning strings and matching patterns with regular expressions is routine in data science work, especially when preparing text corpora for text mining and machine learning, and in everyday Python programming.
Good for: Python users who handle text data and want a structured path through string methods before working with regex syntax and its trickier features.
Keep in mind: Only the second half is about regular expressions; the first two chapters cover plain string methods and formatting, which is useful groundwork rather than regex itself.
Bottom line: Each regex idea is tied to a concrete text task, such as pulling emails out of tweets or filtering phone numbers.
Frequently Asked Questions
What datasets do the exercises use?
String manipulation is practiced on a movie review dataset, formatting on information scraped off the web, and pattern matching on a set of streamed tweets meant for sentiment analysis. Later exercises also parse text taken from PDF files.
Where do regular expressions fit in a data science workflow?
They belong to text mining: extracting key information from large bodies of text, cleaning messy string data and detecting useful words. This preparation happens before machine learning algorithms are applied to the text.
Does it cover lookahead and lookbehind assertions?
Yes. The final chapter treats lookaround alongside backreferences and capturing groups, with exercises that find surrounding words and filter phone numbers using these assertions.
User Reviews
Write your review
You must be logged in to post a review.
Reviews can only be posted by registered learners. Log in or create a free account, then you will return here to post.


There are no reviews yet.