【发布时间】:2016-07-10 22:01:57
【问题描述】:
我正在编写一个 node.JS 应用程序来解析来自谷歌照片的谷歌外卖数据,用于 EXIF 数据。
我不擅长正则表达式,并且尝试过 regexr.com 等网站无济于事,因为有很多未知数。但是我想知道是否有更有效的方法来做到这一点?
假设我可以有各种潜在的字符串
"IMG_20150628_184721-ANIMATION" # There is a date + time within, but they are not in an ISO format, also non-regular characters
"Screenshot_2015-06-27-22-51-00" # Has a date/time at the end, but also has useless string within it
"2015-06-28" # Cleanly formatted date without time
"2015-06-28 22:51:05" # Cleanly formatted date and time
"2015-06-28 #1" # Date + Space and Extra characters that I don't want
"2015-06-28 #3 " # Date + Space and extra characters that I don't want and a trailing space
"2015-06-18-19" # Date + An extra number (happens to be the next day)
"NoDateOrTimeInThisString" # No Date
"IMG_1234" # No date
此列表并非详尽无遗,日期之前+之后可能还有其他字符串。日期/时间也可能实际上不在字符串中
我无法知道最终会使用哪些特定文件名,并且在我的知识范围内,我不知道如何从每个文件名中提取日期。
有没有人知道我将如何在 JavaScript 中执行此操作?例如库?如果可能的话,我希望能够将其放入 JS 日期/时间对象中。但我不知道该怎么做。
【问题讨论】:
标签: javascript regex date datetime time