字符串操作
输入字符串:123#@hello#a111
输出:['123', '#@', 'hello', '#', 'a', '111']
说明:按照 数字,字符,字母进行提取
import re
chars = '123#@hello#a111'
new = []
while len(chars) > 0:
if chars[0].isdigit():
res = re.match(r'\d+', chars).group()
n = len(res)
new.append(res)
chars = chars[n:]
elif chars[0].isalpha():
res = re.match(r'[a-zA-Z]+', chars).group()
n = len(res)
new.append(res)
chars = chars[n:]
else:
res = re.match(r'[^a-zA-Z0-9]+', chars).group()
n = len(res)
new.append(res)
chars = chars[n:]
print(new)