x <- "ABCD"
gsub("(.)(?=.)", "\\1,", x, perl=TRUE)
# => [1] "A,B,C,D"
gsub("(.)(?!$)", "\\1,", x, perl=TRUE)
# => [1] "A,B,C,D"
stringr::str_replace_all(x, "(.)(?!$)", "\\1,")
# => [1] "A,B,C,D"
eCA8LSAiQUJDRCIKZ3N1YigiKC4pKD89LikiLCAiXFwxLCIsIHgsIHBlcmw9VFJVRSkKIyA9PiBbMV0gIkEsQixDLEQiCmdzdWIoIiguKSg/ISQpIiwgIlxcMSwiLCB4LCBwZXJsPVRSVUUpCiMgPT4gWzFdICJBLEIsQyxEIgpzdHJpbmdyOjpzdHJfcmVwbGFjZV9hbGwoeCwgIiguKSg/ISQpIiwgIlxcMSwiKQojID0+IFsxXSAiQSxCLEMsRCI=