1 # 例子1:匹配账户,只能有字母和数字组成,长度限制6-10位 2 r1 = '^[0-9A-Za-z]{6,10}$' 3 a1 = '1234567AbC' 4 print(re.findall(r1,a1)) 5 6 7 # 例子2:匹配qq号:要求纯数字,长度5-11,第一位不为0 8 r2 = r'^[1-9][0-9]{4,10}$' 9 a2 = '123987678' 10 print(re.findall(r2,a2)) 11 12 13 # 例子3:匹配邮箱地址,只允许qq,163,gmail这三种邮箱地址 14 15 r3 = r'(^[\w-]+(\.[\w-]+)*@(qq|163|gmail)(\.[\w-]+)+$)' 16 a3 = '[email protected]' 17 a4 = '[email protected]' 18 print(re.findall(r3,a3)) 19 print(re.findall(r3,a4))
标签:qq,10,正则表达式,re,print,findall,163 From: https://www.cnblogs.com/hd-test/p/18218630