Extract date text from string

后端 未结 1 483
感动是毒
感动是毒 2021-01-24 09:51

I would like to extract date from the following list of text:

[[1]]
[1] \"TAX INVOICE      28 Dec 2018       PO2222\"

[[2]]
[1] \"TAX INVOICE      20 Nov 2018          


        
相关标签:
1条回答
  • 2021-01-24 10:30

    Here is a base R option using lapply and gsub:

    lst <- list("TAX INVOICE      28 Dec 2018       PO2222",
                "TAX INVOICE      20 Nov 2018       PO11111")
    
    lapply(lst, function(x) gsub(".*(\\d{2} \\w{3} \\d{4}).*", "\\1", x))
    [[1]]
    [1] "28 Dec 2018"
    
    [[2]]
    [1] "20 Nov 2018"
    

    Demo

    0 讨论(0)
提交回复
热议问题