我想将字符串拆分为单词[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中实现?
怎么样:
re.findall(r"[A-Za-z@#]+|\S", message)
该模式匹配单词字符的任何序列(在此定义为字母plus@
和#
),或任何单个非空白字符。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句