I have a character vector.
x <- c('This is a simple text', 'this is a veryyyyyyyyyy long word', 'Replacethis andalsothis')
I want to insert a space between a word which is longer than n characters. For this example, we can consider n = 10. I would prefer a regex solution but if you think there are other alternatives I wouldn't mind to try that.
The output that I am looking for -
c('This is a simple text', 'this is a veryyyyyyy yyy long word', 'Replacethi s andalsothi s')
I have tried using the solution from this post by making the necessary changes for my data but it doesn't give the required output.
sub('(.{10})(?=\\S)//g', '\\1 ', x, perl = TRUE)
#[1] "This is a simple text" "this is a veryyyyyyyy long word" "Replacethis andalsothis"