In R I have a character string that looks like the following
x <- c(\"20130603 00:00:03.102\",\"20130703 00:01:03.103\",\"20130804 00:03:03.104\")
The following should work:
gsub("(\\d{4})(\\d{2})(\\d{2})", "\\1-\\2-\\3", subject, perl=TRUE);
i actually came up with the exact same thing as Tim. if you want something more compact try using the stringr package with it.
library(stringr)
str_replace_all("(\d{4})(\d{2})(\d{2})", "$1-$2-$3")