S <- "abcd2efghi2.txt"sub("\\d+(\\D*)$", "\\1", S)
Standard input is empty
[1] "abcd2efghi.txt"
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!