I am having trouble translating this into Ruby.
Here is a piece of JavaScript that does exactly what I want to do:
function get_code(str){ return str
$ variables are only set to matches into the block:
$
"Z_sdsd: sdsd".gsub(/^(Z_.*): .*/) { "#{ $1.strip }" }
This is also the only way to call a method on the match. This will not change the match, only strip "\1" (leaving it unchanged):
strip
"Z_sdsd: sdsd".gsub(/^(Z_.*): .*/, "\\1".strip)