使用Ruby从文本解析日期 [英] Parsing date from text using Ruby

查看:123
本文介绍了使用Ruby从文本解析日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图弄清楚如何使用Ruby从非结构化文本中提取日期.

I'm trying to figure out how to extract dates from unstructured text using Ruby.

例如,我想从此字符串中解析日期将不考虑2010年2月1日午夜(EST)12:00之后开始的应用程序."

For example, I'd like to parse the date out of this string "Applications started after 12:00 A.M. Midnight (EST) February 1, 2010 will not be considered."

有什么建议吗?

推荐答案

假设您只需要日期而不是日期时间:

Assuming you just want dates and not datetimes:

require 'date'
string = "Applications started after 12:00 A.M. Midnight (EST) February 1, 2010 will not be considered."
r = /(January|February|March|April|May|June|July|August|September|October|November|December) (\d+{1,2}), (\d{4})/
if string[r]
  date =Date.parse(string[r])
  puts date
end

这篇关于使用Ruby从文本解析日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆