I have a string like
a <- "Hi. I m cool, but I need help!"
And as an output i would like to have
"hi" "." "I" "m" "cool" "," "but" "I" "need" "help" "!"
Furthermore I don't want to use extra packages.
I have a string like
a <- "Hi. I m cool, but I need help!"
And as an output i would like to have
"hi" "." "I" "m" "cool" "," "but" "I" "need" "help" "!"
Furthermore I don't want to use extra packages.
We can use strsplit
a1 <- strsplit(a, '\\s|(?=[!,.])\\s*', perl = TRUE)[[1]]
a1[nzchar(a1)]
#[1] "Hi" "." "I" "m" "cool" "," "but" "I" "need" "help" "!"