I would like to split a series of strings on the third white space from the right. The number of white spaces varies among string, but each string has at least three white spaces. Here are two example strings.
strings <- c('abca eagh ijkl mnop', 'dd1 ss j, ll bb aa')
I would like:
[1] 'abca', 'eagh ijkl mnop'
[2] 'dd1 ss j,', 'll bb aa'
The closest I have been able to come is:
strsplit(strings, split = "(?<=\\S)(?=\\s(.*)\\s(.*)\\s(.*)$)", perl = TRUE)
which returns:
[[1]]
[1] "abca" " eagh" " ijkl mnop"
[[2]]
[1] "dd1" " ss" " j," " ll bb aa"
I keep thinking the answer should be something like:
strsplit(strings, split = "(?<=\\S\\s(.*)\\s(.*)\\s(.*)$)(?=\\s(.*)\\s(.*)\\s(.*)$)", perl = TRUE)
However, that returns an error. Thank you for any advice. I prefer a solution in base, hopefully one that uses regular expressions.