import re

# info = "姓名:bobby1987 生日:1987年10月1日 本科:2005年9月1日"
#
# # print(re.findall("\d{4}", info))
# match_result = re.match(".*生日.*?(\d{4}).*本科.*?(\d{4})", info)
#
# print(re.search("生日.*\d{4}", info))
#match方法是从字符串的最左边开始匹配
#search不需要从最开始的位置开始匹配

print(match_result.group(1))
# 取第一组的数据
print(match_result.group(2))

替换:

# result = re.sub("\d{4}", "2019", info)

 

 

 

  

posted on 2020-07-17 10:21  topass123  阅读(79)  评论(0编辑  收藏  举报