input = "XSDFADDDDA"gsub("(?:A|(?<!^)\\G)\\K\\p{L}(?=\\p{L}*A)", "A", input, perl=TRUE)
Standard input is empty
[1] "XSDFAAAAAA"
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!