I understand that this is an old question, but since I was looking for a similar answer just now and found it, I thought I would share it.
The simplest and quickest solution I found:
x <- c("AB.38.2", "GF.40.4", "ABC.34.2") only_letters <- function(x) { gsub("^([[:alpha:]]*).*$","\\1",x) } only_letters(x)
And the result:
[1] "AB" "GF" "ABC"
Hope this helps someone!
source share