我想解析一個字符串以獲取包含所有單詞(帶連字符的單詞)的列表。當前的代碼:Python正則表達式字符串到單詞列表(包括帶連字符的單詞)
s = '-this is. A - sentence;one-word'
re.compile("\W+",re.UNICODE).split(s)
回報:
['', 'this', 'is', 'A', 'sentence', 'one', 'word']
,我想它返回:
['', 'this', 'is', 'A', 'sentence', 'one-word']
爲什麼你喜歡的「」? – 2010-08-04 19:39:19