好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

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

我想分割这些字符串

'foofo21'
'bar432'
'foobar12345'

['foofo', '21']
['bar', '432']
['foobar', '12345']

有人知道在python中执行此操作的简单方法吗?

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

match = re.match(r"([a-z]+)([0-9]+)", 'foofo21', re.I)
if match:
    items = match.groups()
    # items is ("foo", "21")

查看更多关于如何将字符串拆分为文本和数字?的详细内容...

  阅读:23次