【发布时间】:2014-10-27 13:09:52
【问题描述】:
我想将字符串拆分为单词 [a-zA-Z] 和它可能包含的任何特殊字符,@ 和 # 符号除外
message = "I am to be @split, into #words, And any other thing that is not word, mostly special character(.,>)"
预期结果:
['I', 'am', 'to', 'be', '@split', ',', 'into', '#words', ',', 'And', 'any', 'other', 'thing', 'that', 'is', 'not', 'word', ',', 'mostly', 'special', 'character', '(', '.', ',', '>', ')']
如何在 Python 中实现这一点?
【问题讨论】:
-
那么,“单词”和“特殊字符”到底是怎么定义的呢?
-
@JoelCornett:我的意思是 ASCII 特殊字符,en.wikipedia.org/wiki/Special_characters
-
不应该
'#words,'是'#word',','? -
@JoelCornett:你知道异常吗?你不明白我的问题吗?
-
@Yax:对不起。我在打电话,没有看到你问题中的第一句话。