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!
To become successful in coding, you need to get out there and solve real problems for real people. That’s how you can become a six-figure earner easily. And 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?
Practice projects is how you sharpen your saw in coding!
Do you want to become a code master by focusing on practical code projects that actually earn you money and solve problems for people?
Then become 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.
Join my free webinar “How to Build Your High-Income Skill Python” and watch 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. He’s author of the popular programming book Python One-Liners (NoStarch 2020), coauthor of the Coffee Break Python series of self-published books, 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.