python3进阶之正则表达式之re模块

re模块

1.match()方法:

  判断是否匹配,如果匹配成功,返回一个Match对象,否则返回None

#示例1:
test1='012-12345678' if re.match(r'^\d{3}\-\d{3,8}$',test1): print('yes') else: print('failed')

#输出
#yes

#说明: ^表示从行头开始匹配,$表示行的结尾,匹配3个数字加-然后3-8个数字  

猜你喜欢

转载自www.cnblogs.com/max520liuhu/p/8934298.html