How to split string by words using regex in Python

1 Answer

0 votes
import re

s = 'Python is an interpreted, general-purpose programming language'

sp = re.split('\W+', s)

print(sp)

 
'''
run:
 
['Python', 'is', 'an', 'interpreted', 'general', 'purpose', 'programming', 'language']
 
'''

 



answered Jul 31, 2019 by avibootz
...