I am trying to remove all the information up to the last / (the year) from this line.
"'CSF0495/DE/wb/1997'"
The code I run goes through but does not remove any information.
This it the code I run
date <- gsub("^[[:alnum:]]{1,}////", "",temp)
It goes through, but does not remove any information. Im not sure what I am missing.
Using sub
sub(".*/", "", "CSF0495/DE/wb/1997")
[1] "1997"
Or with basename
basename("CSF0495/DE/wb/1997")
[1] "1997"
Why not simply extract the year, knowing that it consists of more than one digits extending as far as final position in string ($)?
library(stringr)
str_extract("CSF0495/DE/wb/1997", "\\d+$")
[1] "1997"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With