I have a string named rids.csf. I want to extract csf from it. How I can do it. I tried the following code but it did not work for me.
string<-"rids.csf"
sub(".","", string)
## outcome I got
"ids.csf"
## expected outcome
"csf"
We can match characters (.*
) till the .
(escaped as .
is a metacharacter) and replaced with blank (""
_
sub(".*\\.", "", string)
#[1] "csf"
.
in regex mode (by default it is fixed = FALSE
) matches any character and because of that it matches the first character 'r' and removed it