test.dat <- c("abcde", "abcXe", "abcdY", "abcXY")
gsub("(XY?|Y)", "1\\1", test.dat)

library(stringr)
str_replace_all(test.dat, "(XY?|Y)", "1\\1")