[bigdata-041] python3+re 正则表达式 手机号微信号qq号
来源:互联网 发布:婚礼设计软件 编辑:程序博客网 时间:2024/05/01 12:15
import reREGEX_PHONE = re.compile(r'1\d{10}', re.IGNORECASE)REGEX_QQ = re.compile(r'[1-9]\d{4,10}', re.IGNORECASE)REGEX_WX1 = re.compile(u'微信[\w,-]{1,20}'.encode('utf8'), re.IGNORECASE)#正则手机号码def get_all_phone_num(s1): global REGEX_PHONE return re.findall(REGEX_PHONE, s1)#正则qq号码def get_all_qq_num(s1): global REGEX_QQ return re.findall(REGEX_QQ, s1)#正则微信号码def get_all_weixin_num(s1): global REGEX_WX1, REGEX_WX2, REGEX_WX3 ret = [] res = re.findall(REGEX_WX1, s1.encode('utf8')) #易读性是第一位的,代码长不要紧 for i in res: ret.append(i.decode('utf-8')[2:]) return ret#一个函数获取全部信息def get_phone_qq_wexin(s1): ret = {} ret['mobile']=get_all_phone_num(s1) ret['qq'] = get_all_qq_num(s1) ret['weixin'] = get_all_weixin_num(s1) ret['count'] = len(ret['mobile'])+len(ret['qq'])+len(ret['weixin']) return ret#测试微信号码# ret = get_all_weixin_num(u'我的微信cc-xf889测试我的微信号dd_tt我的微信号码eeff998')# print(ret)
#!/usr/bin/env python3#!-*- coding:utf-8 -*-import re#手机号码"""1、手机号位数为11位;2、第一位是1,后面是任意10个数字则表达式为: ”1\d{9}"""regex = re.compile(r'1\d{10}', re.IGNORECASE)#测试手机号码phonenums = re.findall(regex, "我的wf;aef18717917631dsl13818373801测试")print(phonenums)#qq号码"""1、首先扣扣号开头不能为0;2、QQ号必须大于5且小于11(或12,13,QQ号最长位);则正则表达式为: “[1-9]\\d{4,10}""""regex = re.compile(r'[1-9]\d{4,10}', re.IGNORECASE)qqnums = re.findall(regex,"我的qq261955036测试261955039继续测试")print(qqnums)#微信号码"""1. 微信号可能是手机号可能qq号码也可能是一串字符串2. 开头是"微信",后面有“号”或者没“号”,然后是若干字母"""regex = re.compile(u'微信[\w,-]{1,20}'.encode('utf8'), re.IGNORECASE)res = re.findall(regex, u'我的微信cc-xf889测试我的微信号dd_tt我的微信号码eeff998'.encode('utf8'))for i in res: print(i.decode('utf-8'))regex = re.compile(u'微信号[\w,-]{1,20}'.encode('utf8'), re.IGNORECASE)res = re.findall(regex, u'我的微信cc-xf889测试我的微信号dd_tt我的微信号码eeff998'.encode('utf8'))for i in res: print(i.decode('utf-8'))regex = re.compile(u'微信号码[\w,-]{1,20}'.encode('utf8'), re.IGNORECASE)res = re.findall(regex, u'我的微信cc-xf889测试我的微信号dd_tt我的微信号码eeff998'.encode('utf8'))for i in res: print(i.decode('utf-8'))
0 0
- [bigdata-041] python3+re 正则表达式 手机号微信号qq号
- Python3 re(正则表达式)
- Python3 re(正则表达式)
- 邮箱、手机号、QQ号正则表达式
- 用正则表达式验证邮箱、密码、QQ号、手机号、身份证号
- 正则表达式 python3.x (re模块)
- Python3的正则表达式,re模块
- Python3正则表达式(二)re模块
- 手机号查QQ号(Python3版)
- python3爬虫——正则表达式re详解(1)
- python3爬虫(二) re模块与正则表达式
- 最全正则表达式总结:验证QQ号、手机号、Email、中文、邮编、身份证、IP地址等
- 最全正则表达式总结:验证QQ号、手机号、Email、中文、邮编、身份证、IP地址等
- 最全正则表达式总结:验证QQ号、手机号、Email、中文、邮编、身份证、IP地址等
- 最全正则表达式总结:验证QQ号、手机号、Email、中文、邮编、身份证、IP地址等
- 正则表达式总结:验证QQ号、手机号、Email、中文、邮编、身份证、IP地址等
- 最全正则表达式总结:验证QQ号、手机号、Email、中文、邮编、身份证、IP地址等
- 最全正则表达式总结:验证QQ号、手机号、Email、中文、邮编、身份证、IP地址等
- MyBatis 源码分析——配置信息
- 【BZOJ1036】[ZJOI2008]树的统计Count(树链剖分+线段树)
- 深入浅出 React Native:使用 JavaScript 构建原生应用
- leetcode_middle_12_445. Add Two Numbers II
- 【C++】指针(5):传递指针给函数
- [bigdata-041] python3+re 正则表达式 手机号微信号qq号
- 性能监控与分析
- MyBatis-学习笔记(3)——关联查询
- iOS开发弹出半透明视图
- eclipse中" cannot be resolved to a type"的解决办法
- ThinkPHP模板自定义标签使用方法
- 【C++】指针(6):从函数返回指针
- easy UI的form的submit功能一点小坑
- 凌乱的yyy