参考代码:
mport re strInput = '310.1' strList = re.findall('^[\-\+]?\d+\.?\d+$',strInput) print(strList) strInput2 = 'aa310.0.1' strList2 = re.search('[\-\+]?\d+\.?\d+',strInput2) print(strList2.group()) strInput3 = '310.0.1' strList3 = re.match('[\-\+]?\d+\.?\d+',strInput3) print(strList3.group()) strInput4 = '310.13' strList4 = re.match('^[\-\+]?\d+\.?\d+$',strInput4) if(strList4): res=strList4.group() print(res) else: print("Err")标签:group,处理,re,正则表达式,res,strList4,strInput,print,字符串 From: https://www.cnblogs.com/exesoft/p/16939357.html