If you have some variations of the order of numbers followed by chars, library(stringr)
v1 <- c("absdfds0213451ab", "123abcs4145") pattern=c("[A-Za-z]+", "\\d+") do.call(`Map`,c(c,lapply(pattern, function(.pat) str_extract_all(v1, .pat)))) #[[1]] #[1] "absdfds" "ab" "0213451" #[[2]] #[1] "abcs" "123" "4145" A.K. Hi, If I have a string of consecutive chars followed by consecutive numbers and then chars, like "absdfds0213451ab", how to separate the consecutive chars from consecutive numbers? grep doesn't seem to be helpful grep("[a-z]","absdfds0213451ab", ignore.case=T) [1] 1 grep("[0-9]","absdfds0213451ab", ignore.case=T) [1] 1 Thanks Carol ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.