fork download
  1. input = "123XyzXyzXyz123"
  2. gsub("(?:123|(?<!^)\\G)\\KXyz(?=(?:Xyz)*123)", "A", input, perl=TRUE)
  3.  
Success #stdin #stdout 0.42s 22824KB
stdin
Standard input is empty
stdout
[1] "123AAA123"