remove text after final period in string

前端 未结 4 793
广开言路
广开言路 2020-12-03 13:14

I have a grep puzzle that\'s eluding me: I\'d like to remove the text following the final period in a collection of strings (i am using R, so perl

4条回答
  •  离开以前
    2020-12-03 13:21

    And a non-regex answer for no reason whatsoever:

    test <- c("abc.com.foo.bar","ABCD.txt")
    sapply(strsplit(test,"\\."), function(x) paste0(head(x,-1),collapse=".") )
    #[1] "abc.com.foo" "ABCD"
    

提交回复
热议问题