0
我正在處理文檔,並且我需要將文字隔離而沒有標點符號。我知道如何使用string.split(「」)使每個單詞只是字母,但標點符號讓我感到困惑。從Python中的字符串中剝離標點符號
我正在處理文檔,並且我需要將文字隔離而沒有標點符號。我知道如何使用string.split(「」)使每個單詞只是字母,但標點符號讓我感到困惑。從Python中的字符串中剝離標點符號
這是使用正則表達式的示例,並且其結果是 [ '這個', '是', 'A', '字串', '與', '標點符號']
s = " ,this ?is a string! with punctuation. "
import re
pattern = re.compile('\w+')
result = pattern.findall(s)
print(result)
可以使用正則表達式匹配 – co2y
這個詞的重複[http://stackoverflow.com/questions/265960/best-way-to-strip-punctuation-from-a-string-in-python](http://stackoverflow.com/問題/ 265960 /最佳方式對帶標點符號從 - 一個串入-蟒) – corinna