Try the expression:
(?=(?>\\s\\S*){3}$)\\s
Edit: Use this expression if you want consecutive whitespace characters to be treated as 'one' whitespace:
(?=(?>\\s+\\S*){3}$)\\s
It's worth noting that the reason your expression was causing an error is most likely because most regex engines do not permit variable width lookbehinds. In your example that would be the *
quantifier in the lookbehind breaking the rules.
Got it! Sorry I wasn't 100% on how the strsplit function worked. Try this:
strsplit(strings, split = "(?=(?>\\s+\\S*){3}$)\\s", perl = TRUE)
Here is an example output:
> strings <- c('abca eagh ijkl mnop', 'dd1 ss j, ll bb aa')
> strsplit(strings, split = "(?=(?>\\s+\\S*){3}$)\\s", perl = TRUE)
[[1]]
[1] "abca" "eagh ijkl mnop"
[[2]]
[1] "dd1 ss j," "ll bb aa"