本文實(shí)例為大家分享了python正則提取電話的具體代碼,供大家參考,具體內(nèi)容如下
主要用到正則
import reimport xlrddef is_number(s):#是否數(shù)字 try: x = int(s)#如果可以取整,說(shuō)明是數(shù)字。 return(True) except Exception as e: return Falsedata=xlrd.open_workbook(r'C:/Users/123456/Desktop/手機(jī)號(hào)/號(hào)主.xlsx','utf-8')table = data.sheet_by_name('Sheet1')cols = list(table.col_values(0))f=open(r'C:/Users/123456/Desktop/手機(jī)號(hào)/號(hào)主.txt','w')for i in range(1,100000): print('cols[i]',cols[i],type(cols[i])) if is_number(cols[i]): item=str(int(cols[i]))#xlrd包的結(jié)果可能會(huì)有小數(shù)點(diǎn),因此是數(shù)字的先int一下 else:item=str(cols[i]) result = re.findall("(86)?(1[34578]//d{9})", item)#手機(jī)號(hào)正則匹配 if result != []: f.write(result[0][1] + '/n') print(result[0][1])以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持武林站長(zhǎng)站。
新聞熱點(diǎn)
疑難解答
圖片精選