import re 
#正则的包
line = "huang123"
match_res = re.match('h', line)
#以 h 开头匹配

match_res = re.match('h.', line)
#以h开头后面跟着一个字符
line = 'h\n'
match_res = re.match(r'h\n', line)

line = 'h2k'
match_res = re.match('h.$', line)
以h开头后面只跟着一个字符
line = 'h1m2829'
match_res = re.match('h\d*', line)
以h开头后面跟着任意数量的数字

line = 'hh1m2823'
match_res = re.match('.*3$', line)
以3结尾
line = 'hi3'
match_res = re.match('^h.3$', line)
以h开头,以3结尾,中间只有一个字符

以h开头,以3结尾,中间可以存在任意数量的字符串
if re.match("^h.*3$", line):


regex_string = '1[345678][0-9]{9}'
match_obj = re.match(regex_string, '13722290987')
if match_obj:
print('手机号正确')


posted on 2018-08-23 21:25  卧铺车—站  阅读(133)  评论(0编辑  收藏  举报