str <- paste0(
col_red("I am red---"),
col_green("and I am green-"),
style_underline("I underlined")
)
cat(str, "\n")
# split at dashes, keep color
cat(ansi_strsplit(str, "[-]+")[[1]], sep = "\n")
strsplit(ansi_strip(str), "[-]+")
# split to characters, keep color
cat(ansi_strsplit(str, "")[[1]], "\n", sep = " ")
strsplit(ansi_strip(str), "")
Run the code above in your browser using DataLab