Yes, the dot regex matches whitespace characters when using Python’s
Consider the following example:
import re string = 'The Dot Regex Matches Whitespace Characters' match = re.findall('.', string) print(match) ''' ['T', 'h', 'e', ' ', 'D', 'o', 't', ' ', 'R', 'e', 'g', 'e', 'x', ' ', 'M', 'a', 't', 'c', 'h', 'e', 's', ' ', 'W', 'h', 'i', 't', 'e', 's', 'p', 'a', 'c', 'e', ' ', 'C', 'h', 'a', 'r', 'a', 'c', 't', 'e', 'r', 's'] '''
Try it yourself in our interactive Python shell (click “run”):
The dot matches all characters in the
string–including whitespaces. You can see that there are many whitespace characters
' ' among the matched characters.
Need more info? Watch the simple tutorial video about the dot regex if you need more clarifications:
Note that the dot matches whitespace characters in all other regular expression languages I have found on the web—no matter the programming language or framework.
Do you want to master the regex superpower? Check out my new book The Smartest Way to Learn Regular Expressions in Python with the innovative 3-step approach for active learning: (1) study a book chapter, (2) solve a code puzzle, and (3) watch an educational chapter video.
Where to Go From Here?
Enough theory. Let’s get some practice!
Coders get paid six figures and more because they can solve problems more effectively using machine intelligence and automation.
To become more successful in coding, solve more real problems for real people. That’s how you polish the skills you really need in practice. After all, what’s the use of learning theory that nobody ever needs?
You build high-value coding skills by working on practical coding projects!
Do you want to stop learning with toy projects and focus on practical code projects that earn you money and solve real problems for people?
🚀 If your answer is YES!, consider becoming a Python freelance developer! It’s the best way of approaching the task of improving your Python skills—even if you are a complete beginner.
If you just want to learn about the freelancing opportunity, feel free to watch my free webinar “How to Build Your High-Income Skill Python” and learn how I grew my coding business online and how you can, too—from the comfort of your own home.
While working as a researcher in distributed systems, Dr. Christian Mayer found his love for teaching computer science students.
To help students reach higher levels of Python success, he founded the programming education website Finxter.com that has taught exponential skills to millions of coders worldwide. He’s the author of the best-selling programming books Python One-Liners (NoStarch 2020), The Art of Clean Code (NoStarch 2022), and The Book of Dash (NoStarch 2022). Chris also coauthored the Coffee Break Python series of self-published books. He’s a computer science enthusiast, freelancer, and owner of one of the top 10 largest Python blogs worldwide.
His passions are writing, reading, and coding. But his greatest passion is to serve aspiring coders through Finxter and help them to boost their skills. You can join his free email academy here.