Quantcast
Channel: split string by using regex in python - Stack Overflow
Viewing all articles
Browse latest Browse all 7

split string by using regex in python

$
0
0

What is the best way to split a string like

text = "hello there how are you"

in Python?

So I'd end up with an array like such:

['hello there', 'there how', 'how are', 'are you']

I have tried this:

liste = re.findall('((\S+\W*){'+str(2)+'})', text)for a in liste:    print(a[0])

But I'm getting:

hello there how are you

How can I make the findall function move only one token when searching?


Viewing all articles
Browse latest Browse all 7

Latest Images

Trending Articles





Latest Images