I have a column filename
in a dataframe that looks like this:
/testData/THQ/TAIRATE.20030314.190000.tif
/testData/THQ/TAIRATE.20030314.200000.tif
/testData/THQ/TAIRATE.20030314.210000.tif
/testData/THQ/TAIRATE.20030314.220000.tif
And I want to extract the timestamp from this and store it as another column. But I am not familiar with Regex. So far I have gotten to this:
tdat %>%
dplyr::rowwise() %>%
dplyr::mutate(timestamp = str_extract(as.character(filename), "[^//TAIRATE]+$")) %>%
glimpse()
Result
.20030314.190000.tif
.20030314.200000.tif
.20030314.210000.tif
.20030314.220000.tif
Expected result
20030314190000
20030314200000
20030314210000
20030314220000
Question: How can I write the correct regex or is there a better way?