问题
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