s <- "A12B345CD678"gsub("(?<=.{7}).*$(*SKIP)(*F)|\\D", "", s, perl=T)
Standard input is empty
[1] "12345CD678"
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!