如何分隔包含数字的字符串

时间:2017-06-26 10:02:36

标签: python string split

所以,我有这个字符串: 一个= 'test32' 我想分离这个字符串,所以我在python中得到了两个单独变量中的文本和数字。

1 个答案:

答案 0 :(得分:1)

import re
r = re.compile("([a-zA-Z]+)([0-9]+)")
>>> m=r.match('test32')
>>> m.group(1)
'test'
>>> m.group(2)
'32'
>>>