如何在字符串中拆分数字和字母?所以如果给出:
string = "12really happy15blob"
splitString = []
splitString = mySplitter(string)
print splitString
会返回["12","really happy","15","blob"]
答案 0 :(得分:1)
您可以在此处使用re.split
:
>>> import re
>>> re.split(r'(\d+)', "12really happy15blob")
['', '12', 'really happy', '15', 'blob']
请注意,实际上在字符串的开头和初始12
之间拆分时会得到一个空字符串。如果你不想要它,你必须过滤掉它。