I have used adist to calculate the number of characters that differ between two strings:
adist
a <- \"Happy day\" b <- \"Tappy Pay\" adist(a,b)
You can use one of the variables as a regex character class and gsub out from the other one:
gsub
gsub(paste0("[",a,"]"),"",b) [1] "TP" gsub(paste0("[",b,"]"),"",a) [1] "Hd"