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)
本文来自博客园,作者:topass123,转载请注明原文链接:https://www.cnblogs.com/topass123/p/13328343.html