怎么啦?
ptr1="ptreee765885"
ptr2="hdjfhdjh@@@@"
str1=re.compile(r'[a-zA-Z0-9]+')
result=str1.match(ptr1)
result1=str1.match(ptr2)
if str1.match(ptr2):
print (" string matches %s",ptr2)
else:
print (" string not matches pattern %s",ptr2)发布于 2016-02-09 23:55:26
您需要添加$以匹配字符串的末尾:
str1=re.compile(r'[a-zA-Z0-9]+$')如果需要匹配整个字符串,还应在开头包含^字符以匹配字符串的开头:
str1=re.compile(r'^[a-zA-Z0-9]+$')只有当整个字符串与该选择匹配时,才会匹配。
https://stackoverflow.com/questions/35296283
复制相似问题