You can use the forecast ( (?=\\w\\.) ) And look-behind ( (?<=\\b\\w\\.) ) To target such spaces and replace them with "".
x <- c("AJ Burnett", "Dr. RJ Regex") gsub("(?<=\\b\\w\\.) (?=\\w\\.)", "", x, perl = TRUE) # [1] "AJ Burnett" "Dr. RJ Regex"
Looking ahead corresponds to the word character ( \\w ), followed by a period ( \\. ), And look-behind corresponds to the word boundary ( \\b ), followed by the word character and period.
Jota source share