fork download
  1. text <- c(" Hi, this is a good time to start working together.",
  2. "Hi, this is a good time to start working together.",
  3. "Hi, this is a good time to start working together. ")
  4. gsub("(\\S)\\s{2,}(?=\\S)", "\\1 ", text, perl=TRUE)
  5. stringr::str_replace_all(text, "(\\S)\\s{2,}(?=\\S)", "\\1 ")
  6. ## Or, if the whitespace to leep is the last whitespace in those matched
  7. gsub("(\\S)(\\s){2,}(?=\\S)", "\\1\\2", text, perl=TRUE)
  8. stringr::str_replace_all(text, "(\\S)(\\s){2,}(?=\\S)", "\\1\\2")
Success #stdin #stdout 0.32s 42868KB
stdin
Standard input is empty
stdout
[1] "       Hi, this is a good time to start working together."                  
[2] "Hi, this is a good time to start working together."                         
[3] "Hi, this is a good time to start working together.                         "
[1] "       Hi, this is a good time to start working together."                  
[2] "Hi, this is a good time to start working together."                         
[3] "Hi, this is a good time to start working together.                         "
[1] "       Hi, this is a\tgood\ttime to\tstart working\ttogether."              
[2] "Hi, this is a good time to start working together."                         
[3] "Hi, this is a good time to start working together.                         "
[1] "       Hi, this is a\tgood\ttime to\tstart working\ttogether."              
[2] "Hi, this is a good time to start working together."                         
[3] "Hi, this is a good time to start working together.                         "