Ruby gsub doesn’t escape single-quotes
\’ means $’ which is everything after the match. Escape the \ again and it works “Yaho’o”.gsub(“‘”, “\\\\'”)
\’ means $’ which is everything after the match. Escape the \ again and it works “Yaho’o”.gsub(“‘”, “\\\\'”)
You are looking for “foo /(bar)”.gsub(/(?<my_word> \(.*?\) )/x) do |match| puts “$1 = #{$1} and $my_word = #{$~[:my_word]}” end
Use sub, not gsub. gsub is global, sub isn’t.
Try: name = “^aH^ai” name = name:gsub(“%^a”, “”) See also: http://lua-users.org/wiki/StringLibraryTutorial