如何在Python中将字符串拆分为单词和特殊字符?

Yax*_*Yax 1 python regex string

我想将一个字符串分解成单词[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中实现这一目标?

Blc*_*ght 5

怎么样:

re.findall(r"[A-Za-z@#]+|\S", message)
Run Code Online (Sandbox Code Playgroud)

该模式匹配任何单词字符序列(此处,定义为字母加@#),或任何单个非空白字符.