Match the letter in front of the number and then write the number through the capture group. Then replace the matching characters with \\1\\1means double the number of characters present inside the group index.
> x <- c('JKA1','BP9C','SSTQ3WA')
> gsub("[A-Za-z](\\d)", "\\1\\1", x)
[1] "JK11" "B99C" "SST33WA"
sub for this case will be enough.
> sub("[A-Z](\\d)", "\\1\\1", x)
[1] "JK11" "B99C" "SST33WA"
source
share