↓ 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: https://www.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: https://www.kite.com/get-kite/?utm_medium=referral&utm_source=youtube&utm_campaign=datadaft&utm_content=description-only