首页 > 编程语言 > 详细

python 正则表达式 demo

时间:2015-01-06 15:12:55      阅读:265      评论:0      收藏:0      [点我收藏+]

1、匹配大小写和数字,并且大小写数字均要有,且字符串长度为6~20位

^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])[a-zA-Z\d]{6,20}$

import re
pattern = re.compile("^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])[a-zA-Z\d]{6,20}$")
flag = pattern.match("abcDEF123")
if flag:
print "String matches the pattern."
else:
print "String doesn‘t match the pattern."

(?=.*\d):表示字符串中有数字
(?=.*[a-z]):表示字符串中有小写字母
(?=.*[A-Z]):表示字符串中有大写字母
[a-zA-Z\d]{6,20}:表示字符串中大小写字符和数字总长为6~20之间
^$:分别表示字符串开头和结尾


http://hlee.iteye.com/blog/327993

python 正则表达式 demo

原文:http://www.cnblogs.com/xiaoerlang/p/4205920.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!