你可以使用正则表达式来匹配这个句子中的日期。以下是一个示例代码:

import re

sentence = ",2023-09-01,20230831"

# 匹配日期格式:YYYY-MM-DD
date_pattern = re.findall(r'\d{4}-\d{2}-\d{2}', sentence)
print(date_pattern)

# 匹配数字串
number_pattern = re.findall(r'\d+', sentence)
print(number_pattern)

输出结果为:

['2023-09-01']
['2023', '09', '01', '20230831']

这样你就可以分别得到日期和数字串了。

我有一个句子是:2023-09-0120230831请问如何匹配出2023-09-0120230831

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

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