我想解析一个字符串以获取包含所有单词(带连字符的单词)的列表。当前的代码: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