1 import re 2 input_str = "abcd123.4567.891.123yfdsa4567.54" 3 # 使用正则找出所有数字及下标 4 pattern = re.compile(r"\d+") 5 s = pattern.finditer(input_str) 6 tmp = [] 7 for i in s: 8 tmp.append((i.group(), i.regs[0])) 9 # 求出最大的数及对应下标 10 max_int = max(map(int, [c[0] for c in tmp])) 11 tmp = [i for i in tmp if i[0]==str(max_int)] 12 print(tmp) 13 find = [] 14 for t in tmp: 15 inx = t[1][1] 16 xiaoshu = "" 17 _f = t[0] 18 if len(input_str) != inx and input_str[inx] == ".": 19 _inx = inx 20 for c in range(len(input_str[inx+1:])): 21 if input_str[_inx+1].isdigit(): 22 _inx += 1 23 else: 24 break 25 xiaoshu = input_str[inx+1:_inx+1] 26 print("xiaoshu:", xiaoshu) 27 if xiaoshu: 28 _f = t[0] + "."+xiaoshu 29 find.append(_f) 30 print("===========") 31 find = max(map(float, find)) 32 print(find)