且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

从R中的文本中提取任何格式的日期

更新时间:2023-02-18 09:19:10

我们使用 str_extract 提取它,然后使用 anydate 提取格式

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"