How to split string by words and punctuation using regex in Python

1 Answer

0 votes
import re
 
s = 'Python& is a: , - programming# language!.'
 
sp = re.split('(\W+)', s)
 
print(sp)
 
  
'''
run:
  
['Python', '& ', 'is', ' ', 'a', ': , - ', 'programming', '# ', 'language', '!.', '']
  
'''

 



answered Jul 31, 2019 by avibootz

Related questions

1 answer 177 views
1 answer 151 views
1 answer 188 views
...