I am cleaning some string data using some stringi
functions as part of a pipe.
I would like these functions to be recursive, so that they tackle all the possible occurrences of a re, not only the first one. I cannot predict ex ante the number of times I would need to run the function to properly clean the data.
library(stringi)
test_1 <- "AAA A B BBB"
str_squish(str_remove(x, "\\b[A-Z]\\b"))
result <- "AAA B BBB"
desired <- "AAA BBB"
test_2 <- "AAA AA BBB BB CCCC"
str_replace(test_2,"(?<=\\s[A-Z]{2,3})\\s","")
result <- "AAA AABBB BB CCCC"
desired <- "AAA AABBB BBCCCC"