Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/297.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用正则表达式或任何其他方法从电子邮件字符串中提取所有日期模式的最佳方法?_Python_Regex_Date - Fatal编程技术网

Python 使用正则表达式或任何其他方法从电子邮件字符串中提取所有日期模式的最佳方法?

Python 使用正则表达式或任何其他方法从电子邮件字符串中提取所有日期模式的最佳方法?,python,regex,date,Python,Regex,Date,因此,日期可以是不同的格式,如DD/MM/YYYY或DD/MM或DD-MM-YYYY或DD-MM或DD-month或DDth month或month DDth。对于这些情况,至少我正在试图找到一种优化的方法,从输入字符串(电子邮件)中提取它。除了正则表达式,还有其他方法吗 如果您不想麻烦使用regex(这显然是最好的解决方案),您仍然可以查看已经实现的库,如datefinder: 例如,这家伙让你在文本中查找任何类型的日期: 要安装: 安装日期查找器 import datefinder st

因此,日期可以是不同的格式,如DD/MM/YYYY或DD/MM或DD-MM-YYYY或DD-MM或DD-month或DDth month或month DDth。对于这些情况,至少我正在试图找到一种优化的方法,从输入字符串(电子邮件)中提取它。除了正则表达式,还有其他方法吗

如果您不想麻烦使用regex(这显然是最好的解决方案),您仍然可以查看已经实现的库,如datefinder:

例如,这家伙让你在文本中查找任何类型的日期:

要安装: 安装日期查找器

import datefinder

string_with_dates = "entries are due by January 4th, 2017 at 8:00pm
    created 01/15/2005 by ACME Inc. and associates."

matches = datefinder.find_dates(string_with_dates)

for match in matches:
    print match

# Output
2017-01-04 20:00:00
2005-01-15 00:00:00

问题与机器学习无关-请不要向标签发送垃圾邮件(已删除)。