Python regex separate space-delimited words into a list

list, python, regex, string

Solution

"hello world sample text".split()

will split on any whitespace. If you only want to split on spaces

"hello world sample text".split(" ")

regex version would be something like this

re.split(" +", "hello world sample text")

which works if you have multiple spaces between the words

Problem

If I have a string = "hello world sample text" I want to be able to convert it to a list = ["hello", "world", "sample", "text"] How can I do that with regular expressions? (other methods not using re are acceptable)

Original source