0

I`m working with documents, and I need to have the words isolated without punctuation. I know how to use string.split(" ") to make each word just the letters, but the punctuation baffles me.

XaNaX
  • 53
  • 1
  • 9
  • you can use regex to match the word – co2y May 06 '16 at 03:05
  • duplicate of [http://stackoverflow.com/questions/265960/best-way-to-strip-punctuation-from-a-string-in-python](http://stackoverflow.com/questions/265960/best-way-to-strip-punctuation-from-a-string-in-python) – corinna May 06 '16 at 11:07

1 Answers1

0

this is an example using regex, and the result is ['this', 'is', 'a', 'string', 'with', 'punctuation']

s = " ,this ?is a string! with punctuation. "
import re
pattern = re.compile('\w+')
result = pattern.findall(s)
print(result)
co2y
  • 179
  • 12