gsub("(?:[A-Z]+\\*+|\\G(?!^))\\K\\.(?=[^*]*\\*)", "*", "AG**...**GG*.*.G.*C.C", perl = TRUE)
Standard input is empty
[1] "AG*******GG***.G.*C.C"
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!