Python Regex: How To Match All Whitespace @DataDaft
Python Regex: How To Match All Whitespace  @DataDaft
Uploaded October 2020 | Updated November 2026, 2 hours ago
↓ Code Available Below! ↓

This video shows how to match all whitespace characters using the regular expressions package in Python. Text data often contains words split by whitespace that you might have an interest in extracting, but whitespace separators are not limited to single spaces. You might encounter multiple spaces in a row, tab characters and newlines as well. Python regular expressions make it easy to match and split words on all whitespace.

If you find this video useful, like, share and subscribe to support the channel!
► Subscribe: youtube.com/c/DataDaft?sub_confirmation=1


Code used in this Python Code Clip:

import re

lines = '''Nappa - What does the scouter say about his power level?
Vegeta - It's over 9000!
Nappa - What 9000? That can't be right. \t Can it?'''

re.split(pattern = " ",
string = lines)

# Use \s to match white space:
re.split(pattern = "\s+",
string = lines)

# Use \S to match everything other than whitespace:
re.findall(pattern = "\S+",
string = lines)

* Note: YouTube does not allow greater than or less than symbols in the text description, so the code above will not be exactly the same as the code shown in the video! I will use Unicode large < and > symbols in place of the standard sized ones. .


⭐ Kite is a free AI-powered coding assistant that integrates with popular editors and IDEs to give you smart code completions and docs while you’re typing. It is a cool application of machine learning that can also help you code faster! Check it out here: kite.com/get-kite/?utm_medium=referral&utm_source=youtube&utm_campaign=datadaft&utm_content=description-only
Python Regex: How To Match All WhitespaceCoronavirus New US Cases by State April 1 - May 5How To Use zip() in PythonTallest Buildings In History To Scale (1 pixel = 1 meter)How to Access Columns by Numeric Index in Pandas (Python)How to Access Rows by Numeric Index in Pandas (Python)Python for Data Analysis: ListsAlgorithms Explained: What is an Algorithm?Python Programming Practice: LeetCode #509 - Fibonacci Numberdplyr: selectPython for Data Analysis: Logistic Regressionstringr: Sorting Strings
DataDaft |

Python Regex: How To Match All Whitespace

SHARE TO X SHARE TO REDDIT SHARE TO FACEBOOK WALLPAPER