【问题标题】:how do I separate a string that contains number如何分隔包含数字的字符串
【发布时间】:2017-06-26 10:02:35
【问题描述】:

所以,我有这个字符串: a='test32' 我想分隔这个字符串,以便在 python 中获得两个单独变量中的文本和数字。

【问题讨论】:

标签: python string split


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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-02-07
    • 1970-01-01
    • 1970-01-01
    • 2023-03-13
    • 1970-01-01
    • 2012-02-13
    • 1970-01-01
    相关资源
    最近更新 更多