2016-05-06 74 views
0

我正在處理文檔,並且我需要將文字隔離而沒有標點符號。我知道如何使用string.split(「」)使每個單詞只是字母,但標點符號讓我感到困惑。從Python中的字符串中剝離標點符號

+0

可以使用正則表達式匹配 – co2y

+0

這個詞的重複[http://stackoverflow.com/questions/265960/best-way-to-strip-punctuation-from-a-string-in-python](http://stackoverflow.com/問題/ 265960 /最佳方式對帶標點符號從 - 一個串入-蟒) – corinna

回答

0

這是使用正則表達式的示例,並且其結果是 [ '這個', '是', 'A', '字串', '與', '標點符號']

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