基于python的

编程入门 行业动态 更新时间:2024-10-10 05:18:29

基于<a href=https://www.elefans.com/category/jswz/34/1770869.html style=python的"/>

基于python的

import re
import json# 将语句中不符合手机号码规则的数字串剔除,保存剩余符合手机号码规则的数字到ns中
def is_phone(n):ns = re.findall('\d+', n)  # 提取出word语句中的数字new_list = ns[:]  # 拷贝提取出的数字for i in new_list:if re.match(r'0?(13|14|15|17|18|19)[0-9]{9}', i):  # 判断是否符合普通11位规则的手机号码# print("正确的手机号:", i)ielif re.match("^((\\+86)|(86))?[1][3456789][0-9]{9}$", i):  # 判断是否符合+86规则的手机号码# print("正确的手机号:", i[2:15])ns.remove(i)ns.append(i[2:15])else:# print("错误的手机号:",i)ns.remove(i)return ns# 匹配手机归属地字典,获取需要的信息,并将其按一定格式保存到dics中
def read_Number(n):number = open("手机归属地字典.txt", 'r', encoding='utf-8')  # 读取字典lines = number.readlines()dic = []# 遍历获得的数据for i in n:n = idic.append(n)local = n[0:7]for line in lines:line = line.strip()word = line.split("	")# print(word[1])if local in word[0]:dic.append(word[1])# print(dic)else:continuea = '{手机号:' + dic[0] + ',所属地区|运营商:' + dic[1] + '}'dics = json.dumps(a, ensure_ascii=False)return dics# def cutNumber(ch):
# text = re.findall('\d+', ch)
# return textif __name__ == "__main__":word = "我的电话号码是13945678415,+8615321354556,qq号547749998"print('input:\n%s' % word)# w =cutNumber(word)number = is_phone(word)print('output:')for i in number:w_ = []w_.append(i)print(read_Number(w_))

 

更多推荐

基于python的

本文发布于:2024-02-06 04:40:24,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1746303.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:python

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!