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中实现这一目标?
怎么样:
re.findall(r"[A-Za-z@#]+|\S", message)
Run Code Online (Sandbox Code Playgroud)
该模式匹配任何单词字符序列(此处,定义为字母加@和#),或任何单个非空白字符.
| 归档时间: |
|
| 查看次数: |
3328 次 |
| 最近记录: |