library(stringr)
 
x <- c('123456789', 'kfasdf  3456789asdf', 'a        1')
y <- c('12345 789', '1       9', 'a     678a')
 
str_match(x, regex('(?=[ \\d]{9}(.*$))([ ]*\\d+)\\1$')) [,3]
str_match(y, regex('(?=[ \\d]{9}(.*$))([ ]*\\d+)\\1$')) [,3]