x <- c( "Welcome to A I: the best W O R L D!", "Hi I R is the B O M B for sure: we A G R E E indeed." ) gsub("(?<=[A-Z]) (?=[A-Z] [A-Z])|(?<=[A-Z] [A-Z]) (?=[A-Z])", "", x, perl=TRUE)