码迷,mamicode.com
首页 > 编程语言 > 详细

python 正则表达式 demo

时间:2015-01-06 15:14:36      阅读:179      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!