title: Ruby gsub regex unexpected behaviour
body: <p>I thought I knew regexes pretty well, but this has me puzzled:</p>
  
  <pre><code>irb(main):016:0&gt; source = "/foo/bar"
  =&gt; "/foo/bar"
  irb(main):017:0&gt; source.gsub( /[^\/]*\Z/, "fubar" )
  =&gt; "/foo/fubarfubar"
  </code></pre>
  
  <p>As far as I can tell, <code>/[^\/]*\Z/</code> has a unique expansion to match <code>bar</code> and therefore should result in <code>/foo/fubar</code>. I can't see at all why I get <code>fubarfubar</code> as the replacement.</p>
  
  <p>The replacement works if I call <code>sub</code> rather than <code>gsub</code>, so it's not a question of working around the problem but rather uncovering my misunderstanding of <code>gsub</code>.</p>