且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何将字符串拆分为文本和数字?

更新时间:2022-06-14 21:20:51

我会通过以下方式使用 re.match 来解决这个问题:

I would approach this by using re.match in the following way:

import re
match = re.match(r"([a-z]+)([0-9]+)", 'foofo21', re.I)
if match:
    items = match.groups()
print(items)
>> ("foofo", "21")