Python 正则表达式验证时间格式 2023-04-04 22:00:00
import re
定义正则表达式
pattern = r'^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$'
测试字符串
test_str = '2023-04-04 22:00:00'
判断是否匹配
if re.match(pattern, test_str): print('符合格式') else: print('不符合格式')
原文地址: https://www.cveoy.top/t/topic/mLPc 著作权归作者所有。请勿转载和采集!