you can use sub
sub("\\..*", "", v)
#[1] "7" "8" "12" "11"
or several parameters stringi:
library(stringi)
stri_replace_first_regex(v, "\\..*", "")
#[1] "7" "8" "12" "11"
# extract vs. replace
stri_extract_first_regex(v, "[^\\.]+")
#[1] "7" "8" "12" "11"
If you want to use a separation approach, they will work:
unlist(strsplit(v, "\\..*"))
#[1] "7" "8" "12" "11"
# stringi option
unlist(stri_split_regex(v, "\\..*", omit_empty=TRUE))
#[1] "7" "8" "12" "11"
unlist(stri_split_fixed(v, ".", n=1, tokens_only=TRUE))
unlist(stri_split_regex(v, "[^\\w]", n=1, tokens_only=TRUE))
sub, :
sub("(\\w+).+", "\\1", v)
sub("([[:alnum:]]+).+", "\\1", v)
sub("(\\w+)\\..*", "\\1", v)
sub("(\\d+)\\..*", "\\1", v)
sub("(.+)\\..*", "\\1", v)
stri_extract_first_regex(v, "\\w+")