Ruby gsub doesn’t escape single-quotes

\’ means $’ which is everything after the match.
Escape the \ again and it works

"Yaho'o".gsub("'", "\\\\'")

Leave a Comment