title: Ruby replace string with captured regex pattern
body: <p>I am having trouble translating this into Ruby.</p>
  
  <p>Here is a piece of JavaScript that does exactly what I want to do:</p>
  
  <pre><code>function get_code(str){
      return str.replace(/^(Z_.*): .*/,"$1")​​​​​​​​​​​​​​​​​​​​​​​​​​​;
  }
  </code></pre>
  
  <p>I have tried <a href="http://ruby-doc.org/core-1.9.3/String.html#method-i-gsub">gsub</a>, <a href="http://ruby-doc.org/core-1.9.3/String.html#method-i-sub">sub</a>, and <a href="http://ruby-doc.org/core-1.9.3/String.html#method-i-replace">replace</a> but none seem to do what I am expecting.</p>
  
  <p>Here are examples of things I have tried:</p>
  
  <pre><code>"Z_sdsd: sdsd".gsub(/^(Z_.*): .*/) { |capture| capture }
  "Z_sdsd: sdsd".gsub(/^(Z_.*): .*/, "$1")
  "Z_sdsd: sdsd".gsub(/^(Z_.*): .*/, "#{$1}")
  "Z_sdsd: sdsd".gsub(/^(Z_.*): .*/, "\1")
  "Z_sdsd: sdsd".gsub(/(.).*/) { |capture| capture }
  </code></pre>