input = "AXXXA"
gsub("(?:A|(?<!^)\\G)\\KX(?=X*A)", "A", input, perl=TRUE)
input = "AXXA"
gsub("(?:A|(?<!^)\\G)\\KX(?=X*A)", "A", input, perl=TRUE)
input = "AXA"
gsub("(?:A|(?<!^)\\G)\\KX(?=X*A)", "A", input, perl=TRUE)
aW5wdXQgPSAiQVhYWEEiCmdzdWIoIig/OkF8KD88IV4pXFxHKVxcS1goPz1YKkEpIiwgIkEiLCBpbnB1dCwgcGVybD1UUlVFKQppbnB1dCA9ICJBWFhBIgpnc3ViKCIoPzpBfCg/PCFeKVxcRylcXEtYKD89WCpBKSIsICJBIiwgaW5wdXQsIHBlcmw9VFJVRSkKaW5wdXQgPSAiQVhBIgpnc3ViKCIoPzpBfCg/PCFeKVxcRylcXEtYKD89WCpBKSIsICJBIiwgaW5wdXQsIHBlcmw9VFJVRSk=