x <- c('2020M6','2020M10')sub("(M)([0-9])$", "\\10\\2", x)sub("(M)([0-9])$", "\\10\\2", x, perl=TRUE)
Standard input is empty
[1] "2020M06" "2020M10" [1] "2020M06" "2020M10"
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!