I would try:
#combine all the string in a vector
a<-c(a,b,c)
gsub("(?<=[0-9])(?=[A-Za-z])","\\1 \\2",
gsub("(?<=[a-z])(?=[A-Z0-9])","\\1 \\2",a,perl=TRUE),
perl=TRUE)
#[1] "Diabetes Test In Past 12 months" "Smoking Morethan 12 Pack Years"
#[3] "30 Mins Or Less Exercise"
Simplification a bit:
gsub("(?<=[a-z])(?=[A-Z0-9])|(?<=[0-9])(?=[A-Za-z])"," ",a,perl=TRUE)
gets the same result.
Please note that it is Morethanimpossible to break, because there is no way to know that these are separate words ( Morethanwould).
source
share