以下是一个使用正则表达式匹配日期的示例代码:

import re

date_string = '22.10.2022'

pattern = r'\d{2}\.\d{2}\.\d{4}'

matches = re.findall(pattern, date_string)

if matches:
    print("匹配成功!")
    for match in matches:
        print(match)
else:
    print("未找到匹配的日期")

输出结果:

匹配成功!
22.10.2022
Python正则表达式匹配日期 - 示例代码与解析

原文地址: https://www.cveoy.top/t/topic/qfkd 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录