常用正则匹配(手机,邮箱...)

版权声明:本文为博主原创文章,转载请声明出处。 https://blog.csdn.net/qq_28311921/article/details/79949806

接受一组数据

m = re.match(r'(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s*', content)

匹配姓名{2,4}:名字长度2-4位。 \u4e00-\u9fa5 是中文的编码范围

t1 = re.match(r'[\u4e00-\u9fa5]{2,4}', m.group(1))                  

匹配邮箱

t2 = re.match(r'^[a-zA-Z0-9_.-]+@[a-zA-Z0-9]+(\.[a-zA-Z0-9-]+)*\.[a-zA-Z0-9]{2,6}$', m.group(2))

匹配密码

t3 = re.match(r'\w{5,}', m.group(3))

匹配手机号

t4 = re.match(r"/^1[3|4|5|8][0-9]\d{4,8}$", m.group(4))

匹配生日20XX(年)XX(月)XX(日)

t5 = re.match(r'{19[8-9][0-9]|20[0-1][08]}{0[1-9]|1[0-2]}{0|[1-2][0-9]|3[0-2]}', m.group(5))

“`

猜你喜欢

转载自blog.csdn.net/qq_28311921/article/details/79949806