我使用python在字符串中查找日期,例如:
string01='los mantenimientos acontecieron en los dias 3,06,8 ,9, 15 y 29 de diciembre de 2018.Por cada mantenimiento fué cobrado $1,300.00 códigos de mantenimiento: (3)A34,(2)C54,(1)D65'
(‘管理会议于2018年12月3日、6日、8日、9日、15日和29日举行’)
我首先尝试使用regex来查找和拆分日期和(而不是货币),然后将它们转换为预期的结果
预期结果:['3/12/2018','06/12/2018','08/12/2018','09/12/2018','15/12/2018','29/12/2018']
string02='los mantenimientos sucedieron en: 2,04,05,8,9,10,11,14,15,22,24, y 27 de junio de 2018.Valor de cada uno de los mantenimiento: $1,300.00, códigos de mantenimiento: (1)A35,(6)C54,(5)D65'
(‘管理会议发生在2018年6月2日、4日、5日、8日、9日、10日、11日、14日、15日、22日、24日和27日’)
预期结果:['02/06/2018','04/06/2018','05/06/2018','08/06/2018','09/06/2018','10/06/2018','11/06/2018','14/06/2018','15/06/2018','22/06/2018','24/06/2018','27/06/2018']
我试过了:
dias=re.compile(r"((\s?[0-3]?[0-9]\s?\,?\s?){1,9}[0-3][0-9]|\sy\s[0-3][0-9]\sde\s(?:diciembre|junio)\sde\s[2][0][0-2][0-9])")
dias_found=re.findall(dias,string01)
但是我得到了元组和重复值:
[(' 3,06,8,9, 15', '9, '), (' y 29 de diciembre de 2018', '')]
应该是['3','06','8','9','15','29 de diciembre de 2018']
任何帮助都将不胜感激。你知道吗
提前谢谢。你知道吗
您可以使用
re
模块和字符串操作来轻松提取日期我不知道葡萄牙语的月份名称?(编辑:这是西班牙语),但是用数字替换这些数字是一项很简单的任务。 输出:
相关问题 更多 >
编程相关推荐