我想解析一个字符串以获取包括所有单词(连字符单词也包括在内)的列表。当前的代码如下:
s = '-this is. A - sentence;one-word'
re.compile("\W+",re.UNICODE).split(s)
返回:
['', 'this', 'is', 'A', 'sentence', 'one', 'word']
and I would like it to return:
['', 'this', 'is', 'A', 'sentence', 'one-word']
-this
,但我也不知道更好的解决方案。我感觉除了再次检查结果以删除不需要的负号之外,没有其他方法了。 - Aaron Digulla