Ruby gsub doesn’t escape single-quotes January 7, 2024 by Tarik \’ means $’ which is everything after the match. Escape the \ again and it works "Yaho'o".gsub("'", "\\\\'")