Extract Dates in any format from Text in R

纵然是瞬间 提交于 2020-01-03 06:35:31

问题


I want to Extract Dates from the Given Text , Dates can be in any format April 10 2018, 10-04-2018 , 10/04/2018, 2018/04/10, 04.10.2018 like in other formats ....

I have news data and want to extract dates from the text

for example : My Friend is coming on july 10 2018 or 10/07/2018

i want to extract date from the given text

Please Help

Thanks in advance


回答1:


we extract it using str_extract and then with anydate get the format

library(anytime)
library(stringr)
anydate(str_extract_all(str1, "[[:alnum:]]+[ /]*\\d{2}[ /]*\\d{4}")[[1]])
#[1] "2018-07-10" "2018-10-07"

data

str1 <- "My Friend is coming on july 10 2018 or 10/07/2018"


来源:https://stackoverflow.com/questions/50154466/extract-dates-in-any-format-from-text-in-r

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!