fork download
  1. library(stringr)
  2.  
  3. x <- c('123456789', 'kfasdf 3456789asdf', 'a 1')
  4. y <- c('12345 789', '1 9', 'a 678a')
  5.  
  6. str_match(x, regex('(?=[ \\d]{9}(.*$))([ ]*\\d+)\\1$')) [,3]
  7. str_match(y, regex('(?=[ \\d]{9}(.*$))([ ]*\\d+)\\1$')) [,3]
Success #stdin #stdout 0.24s 42332KB
stdin
Standard input is empty
stdout
[1] "123456789" "  3456789" "        1"
[1] NA NA NA