I have a text that looks like this:
txt <- "w.raw.median"
I want to extract the second word in between two periods ( .
), giving this output
> raw
But why this doesn't work
gsub(".*\\.", "", txt)
What's the right way to do it?
Try this:
gsub(".*\\.(.*)\\..*", "\\1", txt)
[1] "raw"
Also consider
strsplit(txt,'.',fixed=TRUE)[[1]][2]
for a (slightly) more readable version
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.