input = "123XyzXyzXyz123"gsub("(?:123|(?<!^)\\G)\\KXyz(?=(?:Xyz)*123)", "A", input, perl=TRUE)
Standard input is empty
[1] "123AAA123"
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!