x <- c("h a g wells j g verne", "h a g wells j g")gsub("(?<=\\b\\w) (?=\\w\\b)|(?<=\\b\\w)(?= |$)", ".", x, perl=TRUE)
Standard input is empty
[1] "h.a.g. wells j.g. verne" "h.a.g. wells j.g."
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!